Java 使用setVisible()方法处理当前帧时出错
我需要一些帮助。当我按下按钮时,我需要打开一个新窗口并关闭当前窗口。我使用一个匿名函数完成了这项工作,该函数似乎不起作用,因为我收到了一个错误: 对于类型new ActionListener(){},方法setVisible(boolean)未定义 有人能给我一个解决方案,让这个工作吗 提前谢谢 这是我的密码:Java 使用setVisible()方法处理当前帧时出错,java,Java,我需要一些帮助。当我按下按钮时,我需要打开一个新窗口并关闭当前窗口。我使用一个匿名函数完成了这项工作,该函数似乎不起作用,因为我收到了一个错误: 对于类型new ActionListener(){},方法setVisible(boolean)未定义 有人能给我一个解决方案,让这个工作吗 提前谢谢 这是我的密码: loginButton.addActionListener(new ActionListener() { @Override public void
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);
你试过没有
这个的吗?是的,我再也没有收到错误了。谢谢