title: Disposing JFrame with addActionListener using a JButton
body: <p>I have been trying to solve ths problem for the past 3 days :/</p>
  
  <p>I have a class Login() which creates a JFrame-object</p>
  
  <p>Another class named LoginTab() which has a constructor with a JFrame-object as parameter.</p>
  
  <p>I want to dispose the JFrame with a Button in the LoginTab() class. But the addActionListener does not accept the JFrame-object and I don't know why :(</p>
  
  <p>The Code of the LoginTab():</p>
  
  <pre><code>package tabs;
  
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.Insets;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import java.util.Locale;
  import java.util.ResourceBundle;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JPasswordField;
  
  import abstractClasses.JTextFieldImmo;
  import abstractClasses.ValidateInput;
  
  import programs.MySQL;
  import windows.ButtonPanel;
  import windows.UserDetails;
  
  public class LoginTab extends ValidateInput {
  
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  static Locale locale = new Locale("de");
  static ResourceBundle r = ResourceBundle.getBundle("Strings", locale);
  
  // static Connection con = null;
  static Statement stnt = null;
  static ResultSet rs = null;
  
  public LoginTab(JFrame window) {
      panelMethod(window);
  }
  
  // LOGIN ITEMS
  JLabel usernameLbl = new JLabel(r.getString("username"));
  JLabel passwordLbl = new JLabel(r.getString("password"));
  JTextFieldImmo usernameFld = new JTextFieldImmo(10);
  JPasswordField passwordFld = new JPasswordField(10);
  JButton loginBtn = new JButton(r.getString("login"));
  JButton registerUserBtn = new JButton("Neuer Benutzer"); // TODO String
                                                              // einfügen
  
  public void panelMethod(JFrame window) {
  
      this.setLayout(new GridBagLayout());
  
      GridBagConstraints c = new GridBagConstraints();
  
      // Insets
      c.insets = new Insets(4, 5, 0, 0);
  
      c.fill = GridBagConstraints.HORIZONTAL;
      c.gridx = 0;
      c.gridy = 0;
      this.add(usernameLbl, c);
  
      c.fill = GridBagConstraints.HORIZONTAL;
      c.gridx = 1;
      c.gridy = 0;
      this.add(usernameFld, c);
  
      c.fill = GridBagConstraints.HORIZONTAL;
      c.gridx = 0;
      c.gridy = 1;
      this.add(passwordLbl, c);
  
      c.fill = GridBagConstraints.HORIZONTAL;
      c.gridx = 1;
      c.gridy = 1;
      this.add(passwordFld, c);
  
      c.fill = GridBagConstraints.HORIZONTAL;
      c.gridx = 1;
      c.gridy = 2;
      this.add(loginBtn, c);
  
      c.fill = GridBagConstraints.HORIZONTAL;
      c.gridx = 0;
      c.gridy = 2;
      this.add(registerUserBtn, c);
  
      // Actions Listener
  
  
      loginBtn.addActionListener(new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
              try {
                  MySQL.connect();
                  String username = usernameFld.getText().trim();
                  String password = String.valueOf(passwordFld.getPassword())
                          .trim();
  
                  String sql = "SELECT username,password from per_user where username = '"
                          + username + "'and password = '" + password + "'";
                  stnt = MySQL.getCon().createStatement();
                  rs = stnt.executeQuery(sql);
  
                  int count = 0;
  
                  while (rs.next()) {
                      count = count + 1;
                  }
  
                  if (count == 1) {
                      JOptionPane.showMessageDialog(null, "User Found, Access Granded!"); //TODO String
                      //window.setVisible(false);
                      //window.dispose();
                      new ButtonPanel();
                  } else if (count &gt; 1) {
                      JOptionPane.showMessageDialog(null,
                              "Duplicate User, Access Denied!"); // TODO String einfügen
                  } else {
                      JOptionPane.showMessageDialog(null, "User not Found"); // TODO String einfügen
                  }
  
              } catch (Exception e1) {
                  // JOptionPane.showMessageDialog(null,
                  // "Es konnte keine Verbindung zum MySQL Server hergestellt werden.");
                  e1.printStackTrace();
              }
  
          }
      });
  
      registerUserBtn.addActionListener(new ActionListener() {
  
          @Override
          public void actionPerformed(ActionEvent arg0) {
              new UserDetails();
          }
      });
  
      passwordFld.addActionListener(new ActionListener() {
  
          @Override
          public void actionPerformed(ActionEvent arg0) {
              loginBtn.doClick();
  
          }
      });
  }
  }        
  </code></pre>
  
  <p>        </p>