Java button and listener not working in sync <p><em>Trying to add a button to an already made program in JAVA. It converts temperature from Fahrenheit to celsius. My button won't show up. I'm missing something. The idea is that you will be able to both press enter or the button to have a result. There's the main part of the program:</em></p> <pre><code>import javax.swing.JFrame; public class Fahrenheit { public static void main (String[] args) { JFrame frame = new JFrame ("Fahrenheit"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); FahrenheitPanel panel = new FahrenheitPanel(); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } } </code></pre> <p><em><strong>Then in a separate file:</em></strong></p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; public class FahrenheitPanel extends JPanel { private JLabel inputLabel, outputLabel, resultLabel; private JButton push; private JTextField fahrenheit; //----------------------------------------------------------------- // Constructor: Sets up the main GUI components. //----------------------------------------------------------------- public FahrenheitPanel() { inputLabel = new JLabel ("Enter Fahrenheit temperature:"); outputLabel = new JLabel ("Temperature in Celsius: "); resultLabel = new JLabel ("---"); fahrenheit = new JTextField (5); fahrenheit.addActionListener (new TempListener()); add (inputLabel); add (fahrenheit); add (outputLabel); add (resultLabel); //Here's some button code push = new JButton ("Push!!!"); push.addActionListener (new ButtonListener()); add (push); setPreferredSize (new Dimension(300, 75)); setBackground (Color.red); } private class ButtonListener implements ActionListener { private class TempListener implements ActionListener { //-------------------------------------------------------------- // Performs the conversion when the enter key is pressed in // the text field. //-------------------------------------------------------------- public void actionPerformed (ActionEvent event) { int fahrenheitTemp, celsiusTemp; String text = fahrenheit.getText(); fahrenheitTemp = Integer.parseInt (text); celsiusTemp = (fahrenheitTemp-32) * 5/9; resultLabel.setText (Integer.toString (celsiusTemp)); } } } } </code></pre>