// SwingGui Example // Source code file MyForm.java // This GUI converts a Celsius // temperature to Fahrenheit import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class MyForm { private JTextField txtCelsius; private JPanel panel1; private JTextField txtFahrenheit; private JButton btnConvert; public MyForm() { btnConvert.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int cel = Integer.parseInt(txtCelsius.getText( )); int fahr = 9 * cel / 5 + 32; String output = String.valueOf(fahr); JOptionPane.showMessageDialog( null, "Fahrenheit Temperature: " + output); txtFahrenheit.setText(output); } }); } public static void main(String[ ] args) { JFrame frame = new JFrame("Cel2Fahr Example"); MyForm form = new MyForm( ); frame.setContentPane(form.panel1); //frame.pack( ); frame.setSize(400, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }