How to add ActionListener to JButton
<p>I know I can add ActionListener to JButton if I declare JButton with a name.</p>

<pre><code>JButton showDialogButton = new JButton("Click Me");

    showDialogButton.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        // display/center the jdialog when the button is pressed
        JDialog d = new JDialog(frame, "Hello", true);
        d.setLocationRelativeTo(frame);
        d.setVisible(true);
      }
    });
</code></pre>

<p>But what should I do if I have the following code:</p>

<pre><code>MyJFrame frame = new MyJFrame();
frame.setSize(500,300);
JPanel base = new JPanel();

base.setLayout(new BorderLayout());

JPanel north = new JPanel();

north.add(new JLabel("Name"));
north.add(new JTextField());
north.add(new JButton("Enter"));
north.add(new JButton("Exit"));
</code></pre>

<p>I would appreciate any answer.</p>