Monday 15 February 2010

java - Disposing JFrame with addActionListener using a JButton -


I have been trying to solve the ths problem from the last 3 days: /

I have A class is logged () which creates a JFrame-object

Another category named LoginTab () which is a constructor with a JFrame-object as parameter.

LoginTab ()

I want to dispose of JFrame with a button in the login tab () but addActionListener does not accept the JFrame object and I do not know why: Code:

  Package tab; 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 abstractClasse S.JTextFieldImmo; Import abstractClasses.ValidateInput; Import programs.MySQL; Import windows.ButtonPanel; Import windows.UserDetails; Public class LoginTab extends ValidateInput {/ ** * * / Private static last long serialVersionUID = 1L; fixed locale locale = new locale ("D"); Static ResourceBundle r = ResourceBundle.getBundle ("Strings", Locale); // Static Connection Con = Null; Static statement stnt = null; Fixed result set rs = null; Public LoginTab (JFrame Window) {Panel Method (Window); } // log in items JLBL userNLLL = new JLabel (R.Jest string ("Username")); Jellabell passwordll = new jlabell (r.getString ("password")); JTextFieldImmo Username Fld = New JTextFieldImmo (10); Japjewardfield passwordflood = new japjewardfield (10); Pocket button button = new pocket (r.getstring ("login")); Jebton Register User BTN = New Pocket ("Neur Benutter"); // TODO string // einfügen Public Zero Panel Method (JFrame Window) {this.setLayout (New GridBagLayout ()); Gridbag Consultants c = New Gridbag Consultants (); // Ints c.insets = new wrapper (4, 5, 0, 0); C.fill = GridBagConstraints.HORIZONTAL; C.gridx = 0; C. Grady = 0; This.add (usernameLbl, c); C.fill = GridBagConstraints.HORIZONTAL; C.gridx = 1; C. Grady = 0; This.add (usernameFld, c); C.fill = GridBagConstraints.HORIZONTAL; C.gridx = 0; C.gridy = 1; This.add (passwordll, 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 (Register UserBtn, c); // Action Listener loginBtn.addActionListener (New ActionListener) {@Override Public Zero ActionPerformed (ActionEvent e) {MySQL.connect () try {; String Username = usernameFld.getText () trim (); String Password = String ValueOf (passwordFld.getPassword ()) .trim (); string sql = '+ username + "and password =' ​​'+ + password' ''" "per_user where username selects username, password" '; stnt = MySQL.getCon () .createStatement (); rs = stnt.executeQuery (sql); int count = 0; while (rsnext ()) {count = count + 1;} if (count == 1) {JOptionPane.showMessageDialog (Null, "user found, ex Es grande! "); // tudo string // windows. Cetswizle (floss); // vando dijos (new); new buttonpennell ();} and if (calculation> 1) {JOptionPane.showMessageDialog (" tap, "duplicate User, Access Denied! "); // Todo String einfügen} and {Joppenpen. Show Message Dialege (blank," user not found "); // Todo string infra ¼ gene}} hold (exception e1) {// joppenpenn ShowMessageDialog (empty, // "Es cone cine verbundung zoom on M YSQL server horastile Dan. "); E1.printStackTrace ();}}}; RegisterUserBtn.addActionListener (New Executionist) {@ Override Public Records ActionPerfed (ActionAut RJX) {New User Defence ();}}); PasswordFld.addActionListener (New Executioner } {@ Override Public Wide ActionPerfed (ActionAut RG02) {loginBtn.doClick ();}})}}   

exit and then send a closest request to that window. Can also be used to close the window.

No comments:

Post a Comment