使用setVisible()方法错误以配置当前帧

时间:2015-11-07 12:40:22

标签: java

我需要一些帮助。当我按下按钮时,我需要打开一个新窗口并关闭当前窗口。我使用匿名函数完成了这项工作,这似乎没有用,因为我收到错误:

  

方法setVisible(boolean)未定义类型new ActionListener(){}

有人可以给我一个解决方案吗?

提前致谢!

这是我的代码:

loginButton.addActionListener(new ActionListener() {



        @Override
        public void actionPerformed(ActionEvent e) {
            Login.user = "root";
            Login.pass = "aaaa";
            Login.schema = "bankingdb";

            try {
                conn = MySql.getConnection(user, pass, "/" + schema);
                connection = true;

                try {
                    String q = "select usertype from create_user where username=? and password=?";
                    PreparedStatement stmt = conn.prepareStatement(q);
                    stmt.setString(1, userBox.getText());
                    stmt.setString(2, passwordBox.getText());
                    ResultSet rs = stmt.executeQuery();

                    if (rs.next()) {
                        if (rs.getString("usertype").equals("Admin")) {
                            AdminMenu adminMenu = new AdminMenu();
                            adminMenu.setVisible(true);
                            this.setVisible(false);
                        } else if (rs.getString("usertype").equals("Employee")) {
                            UserFrame obj = new UserFrame();
                            // obj.setVisible(true);
                            // this.setVisible(false);
                        }
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "Invalid Username/Password");
                    }

                    stmt.execute();
                    stmt.close();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(rootPane, "Error in Query: " + ex.getMessage());
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, "Error in connection: " + ex.getMessage());
            }
        }
    });

以下是我收到错误的行:

this.setVisible(false);

0 个答案:

没有答案