The complete application is below:
Of course, you will want to copy this to a file, compile and run it.
import java.awt.*; import java.awt.event.*; import javax.swing.* ; public class FahrConvert extends JFrame implements ActionListener { JLabel title = new JLabel("Convert Fahrenheit to Celsius"); JLabel inLabel = new JLabel("Fahrenheit "); JLabel outLabel = new JLabel("Celsius "); JTextField inFahr = new JTextField( 7 ); JTextField outCel = new JTextField( 7 ); int fahrTemp ; int celsTemp ; FahrConvert() { getContentPane().setLayout( new FlowLayout() ); inFahr.addActionListener( this ); getContentPane().add( title ); getContentPane().add( inLabel ); getContentPane().add( outLabel ); getContentPane().add( inFahr ); getContentPane().add( outCel ); outCel.setEditable( false ); setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ); } public void convert( ) { celsTemp = ((fahrTemp-32) * 5) / 9; } public void actionPerformed( ActionEvent evt) { String userIn = inFahr.getText() ; fahrTemp = Integer.parseInt( userIn ) ; convert() ; outCel.setText( celsTemp+" " ); repaint(); } public static void main ( String[] args ) { FahrConvert fahr = new FahrConvert() ; fahr.setSize( 200, 150 ); fahr.setVisible( true ); } }