title: I can't handle a JButton click event using actionPerformed() method, don't enter in the method, why?
body: <p>I am pretty new in Java <strong>Swing</strong> and I have some problem trying to handle the click event on a button by the use pf the <strong>ActionPerformed</strong> method, like in the documentation: <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/button.html#abstractbutton" rel="nofollow">http://docs.oracle.com/javase/tutorial/uiswing/components/button.html#abstractbutton</a></p>
  
  <p>So I have this <strong>LoginFrame</strong> class:</p>
  
  <pre><code>package com.test.login;
  
  import javax.swing.JButton;
  
  import java.awt.Container;
  import java.awt.Dimension;
  import java.awt.event.ActionEvent;
  import java.io.IOException;
  
  import javax.swing.ImageIcon;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JPopupMenu.Separator;
  import javax.swing.JTabbedPane;
  import javax.swing.JTextField;
  
  import net.miginfocom.swt.MigLayout;
  
  import org.jdesktop.application.SingleFrameApplication;
  
  public class LoginFrame extends SingleFrameApplication {
  
      private static final int FIXED_WIDTH = 550;
      private static final Dimension INITAL_SIZE = new Dimension(FIXED_WIDTH, 230);
  
      private boolean loginResult = true;
  
      /*
      public static void main(String[] args) {
          System.out.println("DENTRO: LoginFrame() ---&gt; main()");
          launch(LoginFrame.class, args);
      }
      */
  
      @Override
      protected void startup() {
          // TODO Auto-generated method stub
          System.out.println("Inside LoginFrame ---&gt; startup()");
  
  
          JFrame loginFrame = this.getMainFrame();            // main JFrame that represents the Windows
          loginFrame.setTitle("XCloud Login");
  
          loginFrame.setPreferredSize(INITAL_SIZE);
          loginFrame.setResizable(false);
  
          Container mainContainer = loginFrame.getContentPane();      // main Container into the main JFrame
  
  
          // JPanel creation and settings of the MigLayout on it:
          // JPanel externalPanel = new JPanel();
          JPanelWithBackground externalPanel = null;
  
          try {
              externalPanel = new JPanelWithBackground("resources/logo.png");
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          externalPanel.setLayout(new net.miginfocom.swing.MigLayout("fill"));
  
          externalPanel.add(new JLabel("Username"), "w 50%, wrap");
  
          JTextField userNameTextField = new JTextField(20);
  
          externalPanel.add(userNameTextField, "w 90%, wrap");
  
          externalPanel.add(new JLabel("Password"), "w 50%, wrap");
          JTextField pswdTextField = new JTextField(20);
          externalPanel.add(pswdTextField, "w 90%, wrap");
  
          JButton loginButton = new JButton("Login");
          loginButton.setActionCommand("loginAction");
  
          externalPanel.add(loginButton, "w 25%, wrap");
  
          mainContainer.add(externalPanel);
          //mainFrame.add(mainContainer);
  
          show(loginFrame);
  
  
      }
  
      // Operation performed when the loginButton is clicked:
      public void actionPerformed(ActionEvent e) {
          System.out.println("Inside LoginFrame ---&gt; actionPerformed()");
          if ("loginAction".equals(e.getActionCommand())) {
              System.out.println("loginButton clcked !!!");
  
          }
      }
  
  }
  </code></pre>
  
  <p>As you can see in this class I have a <strong>JButton</strong> named <strong>loginButton</strong> and on this object I have set an <strong>ActionCommand</strong>, in this way:</p>
  
  <pre><code>JButton loginButton = new JButton("Login");
  loginButton.setActionCommand("loginAction");
  </code></pre>
  
  <p>Then I have create the following <strong>actionPerformed</strong> that have to handle this event:</p>
  
  <pre><code>// Operation performed when the loginButton is clicked:
  public void actionPerformed(ActionEvent e) {
      System.out.println("Inside LoginFrame ---&gt; actionPerformed()");
      if ("loginAction".equals(e.getActionCommand())) {
          System.out.println("loginButton clcked !!!");
  
      }
  }
  </code></pre>
  
  <p>So this method take the <strong>ActionCommand</strong> inside the event and if it is equals to <strong>loginAction</strong> print a message.</p>
  
  <p>The problem is that don't enter in the <strong>actionPerformed()</strong> method (don't print the "Inside LoginFrame ---> actionPerformed()" string in the Eclipse console), so I can't handle this click event.</p>
  
  <p>Why? what am I missing?</p>
  
  <p>Tnx</p>
  
  <p>Andrea</p>