Temp Converter
<< Nifty Scrolling Game | LabTrailIndex | Simple Function Graph >>
Temperature.java
FahrenheitToCelsius.java
here is a nice GUI application that converts degrees to celsius
/** * FahrenheitToCelcius uses the CF Class. * * @author Fr Chris * @version 1.0 28 Jan 2007 */ import java.awt.*; import java.awt.event.*; class FahrenheitToCelsius extends Frame implements ActionListener { TextField input; TextField output; Button toc; public FahrenheitToCelsius() { super("Fahrenheit to Celsius"); input = new TextField(15); output = new TextField(15); output.setEditable(false); toc = new Button("To Celsius"); toc.addActionListener(this); setLayout(new FlowLayout()); add(input); add(toc); add(output); this.addWindowListener (new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } ); setSize(400,200); } public void actionPerformed(ActionEvent ev) { String txt = input.getText(); double degrees = Double.parseDouble(txt); double celsius = Temperature.toCelsius(degrees); //Note that this requires the static Method toCelcius in the Temperature class String s = Double.toString(celsius); output.setText(s); } public static void main(String args[]) { FahrenheitToCelsius app = new FahrenheitToCelsius(); app.setVisible(true); } }