/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package windowtest; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * * @author jcmt */ public class FahrenheitPanel extends JPanel { private JLabel inputLabel, outputLabel, resultLabel; private JTextField fahrenheit; public FahrenheitPanel() { inputLabel = new JLabel("Enter Fahrenheit temp:"); outputLabel = new JLabel("Temp in Celsius: "); resultLabel = new JLabel("---"); fahrenheit = new JTextField(5); fahrenheit.addActionListener(new TempListener() ); add(inputLabel); add(fahrenheit); add(outputLabel); add(resultLabel); } private class TempListener implements ActionListener { public void actionPerformed(ActionEvent event) { int fTemp, cTemp; String text = fahrenheit.getText(); fTemp = Integer.parseInt(text); cTemp = (fTemp - 32) * 5/9; resultLabel.setText(Integer.toString(cTemp)); } } }