title: ClassCastException: javax.swing.JButton
body: <p>All I want is to make a simple user password login.</p>
  
  <p>I have put there an <code>ActionListener</code> and when I press log in just pop up the password and check if it's good.</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.GridLayout;
  import java.awt.Insets;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JPasswordField;
  import javax.swing.JTextField;
  
  public class PasswordForm 
  {
      private static String password = "mypass";
      public static void main(String[] args)
      {
          // Basic form create
          JFrame frame = new JFrame("Form 1");
          frame.setSize(300,300);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          // Creating the grid
          JPanel panel = new JPanel(new GridBagLayout());
          frame.getContentPane().add(panel, BorderLayout.NORTH);
          GridBagConstraints c = new GridBagConstraints();
  
          // Create some elements
          JTextField usernameInput = new JTextField(10);
          c.gridx = 0;
          c.gridy = 1;
          panel.add(usernameInput,c);
  
          JPasswordField passwordInput = new JPasswordField(10);
          c.gridx = 0;
          c.gridy = 2;
          panel.add(passwordInput,c);
  
          JButton loginInput = new JButton("Login");
          c.gridx = 0;
          c.gridy = 3;
          loginInput.addActionListener(new LoginButton());
          panel.add(loginInput,c);
  
  
          frame.setVisible(true);
      }
  
      static class LoginButton implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
              JTextField usernameInput = (JTextField)e.getSource();
              JOptionPane.showMessageDialog(null,"Text is:");
          }
      }
  }
  </code></pre>
  
  <p>Anyone with help?</p>
  
  <p>error</p>
  
  <pre><code>    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JButton
  at PasswordForm$LoginButton.actionPerformed(PasswordForm.java:56)
  at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
  at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
  at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
  at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
  at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
  at java.awt.Component.processMouseEvent(Unknown Source)
  at javax.swing.JComponent.processMouseEvent(Unknown Source)
  at java.awt.Component.processEvent(Unknown Source)
  at java.awt.Container.processEvent(Unknown Source)
  at java.awt.Component.dispatchEventImpl(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
  at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
  at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
  at java.awt.Container.dispatchEventImpl(Unknown Source)
  at java.awt.Window.dispatchEventImpl(Unknown Source)
  at java.awt.Component.dispatchEvent(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>