CSCI 161: Introduction to Programming I
Spring 2007
Lab 7: Temperature Conversion
(Writing Classes, Conditionals, and Event Handling)
Due Thursday, March 29th at beginning of lab
period
Prompt the user for a temperature in degrees Centigrade. Convert the inputted temperature to degrees Fahrenheit, changing the background color to blue if the temperature is cold, green if the temperature is intermediate, and red if it is hot. (While we think of red objects as hot and blue objects as cold, the opposite is usually true. Hotter objects emit waves with higher frequencies, and blue light has a higher frequency than red light.)
Using a JTextField, prompt the user for a double floating point temperature in degrees Centigrade.
After the user presses the Enter key or clicks a Convert JButton, calculate the equivalent temperature in degrees Fahrenheit. Output this number in a JLabel. Change the background color to blue if the resulting temperature is at most 40 degrees F, green if it is at most 74 F, and red if it is over 74 F.
public void actionPerformed (ActionEvent event) to respond to the user pressing the Enter key or clicking the button. Note: You only need ONE listener and one actionPerformed method.
Listings 4.12 and 4.13 in the text will prove useful.