Starting from:
$35

$29

CS1811 Getting Warmer Solved

Purpose

To review the basics of user interfaces




Directions

Create an interface for a program converts between the Fahrenheit and Celsius temperature scales. When the user types in a number in the Fahrenheit text field and clicks on the Convert button, the program should display the corresponding temperature in Celsius in that text field. If the user enters an invalid value or the Fahrenheit text box is empty when the Convert button is clicked, the GUI should handle the exception without crashing.










For an extra (completely optional) challenge: Try modifying your program so that it reads the value from whichever text field was most recently typed in and displays the equivalent in the other text field. So, for example, if the user types 32 in the Fahrenheit text field, your program should display 0 in the Celsius text field. If the user then types 100 in the Celsius text field, it should display 212 in the Fahrenheit text field. You can do this by creating a variable of type JTextField called something like lastEdited and adding KeyListeners to both of the text fields. Then you can modify the button action handler to take the appropriate action based on which text field was last typed in. Here is an example of a key event handler:

fahrenheitTF.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) {
lastEdited = (JTextField) e.getSource();
}
});

More products