Java Reference
In-Depth Information
private class
CelsHandler
implements
ActionListener
{
public void
actionPerformed(ActionEvent e)
{
double
celsius, fahrenheit;
celsius =
Double.parseDouble(celsiusTF.getText());
fahrenheit = celsius * CTOF + OFFSET;
fahrenheitTF.setText(String.format("%.2f",
fahrenheit));
}
}
private class
FahrHandler
implements
ActionListener
{
public void
actionPerformed(ActionEvent e)
{
double
celsius, fahrenheit;
fahrenheit =
Double.parseDouble(fahrenheitTF.getText());
celsius = (fahrenheit - OFFSET) * FTOC;
celsiusTF.setText(String.format("%.2f",
celsius));
}
}
public static void
main(String[] args)
{
TempConversion tempConv =
new
TempConversion();
}
}
Sample Run: (Figure 6-10 shows the display after the user typed
98.60
in the text
field
Temp in Fahrenheit
and pressed
Enter
.)
FIGURE 6-10
Sample run for
TempConversion
Search WWH ::
Custom Search