title: JButton ActionListener doesn't work (in Eclipse plugin)
body: <hr>
  
  <h2>Question resolved:  I mixed up <a href="https://developers.google.com/java-dev-tools/wbpro/" rel="nofollow noreferrer">windowbuilder</a>'s  quickly test/preview button with eclipse's compile button:</h2>
  
  <p><img src="https://i.stack.imgur.com/8Wgkd.png" alt="enter image description here">
  (only found out by 'accidentally' pausing my mouse on the button and seeing that it doesn't compile)</p>
  
  <hr>
  
  <p><strong>Original question</strong></p>
  
  <p>I have a very specific issue:</p>
  
  <p>I have two different classes:</p>
  
  <ul>
  <li><p>Class 1 implements a JPanel within a JFrame.</p></li>
  <li><p>Class 2 implements a JFrame only.</p></li>
  </ul>
  
  <p>In Class 2, the following code works perfectly:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.EventQueue;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.border.EmptyBorder;
  import javax.swing.JButton;
  import javax.swing.JTextField;
  import java.awt.event.ActionListener;
  import java.awt.event.ActionEvent;
  import javax.swing.JTextPane;
  import java.awt.event.KeyAdapter;
  import java.awt.event.KeyEvent;
  
  public class frameTest extends JFrame {
  
  private JPanel contentPane;
  private JTextField txtGeefLiefde;
  
  /**
   * Launch the application.
   */
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
                  frameTest frame = new frameTest();
                  frame.setVisible(true);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
  
  /**
   * Create the frame.
   */
  public frameTest() {
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(100, 100, 450, 300);
      contentPane = new JPanel();
      contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
      setContentPane(contentPane);
      contentPane.setLayout(null);
  
      JButton btnTest = new JButton("press");
  
      btnTest.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              testFunction();
          }
      });
      btnTest.setBounds(162, 188, 89, 23);
      contentPane.add(btnTest);
  
  }
  
  public void testFunction()
  {
      JTextPane textPane = new JTextPane();
      textPane.setBounds(162, 231, 89, 20);
      textPane.setText(":)");
      contentPane.add(textPane);
  }
  
  }
  </code></pre>
  
  <p>Now I want to implement the exact same functionality in Class 1 as well.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>    import java.awt.event.MouseAdapter;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;
      import java.awt.event.MouseEvent;
  
      public class frontpanel extends JFrame {
  
      private JPanel panel;
  
  /**
   * Launch the application.
   */
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
                  frontpanel frame = new frontpanel();
                  frame.setVisible(true);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
  
  /**
   * Create the frame.
   */
  public frontpanel() {
  
              JButton btnTest = new JButton("press");
  
              btnTest.addActionListener(new ActionListener() {
                     public void actionPerformed(ActionEvent e) {
  
                          testFunction();
  
                     }
              });
              btnTest.setBounds(162, 188, 89, 23);
              panel.add(btnTest);
      }
          public void testFunction()
          { 
          JTextPane textPane = new JTextPane();
          textPane.setBounds(162, 231, 89, 20);
          textPane.setText(":)");
          panel.add(textPane);
          }
      }
  </code></pre>
  
  <p>where <code>panel</code> is the JPanel in the JFrame.</p>
  
  <p>I have been stuck on this for hours. I just can't seem to get ANY <code>ActionListener</code> to work. What is causing the problem?</p>
  
  <p>All help greatly appreciated!</p>