我正在尝试实现以下目标:显示登录窗口,然后从工厂确定GUIclass
要打开的内容(例如admin
/ dev
/ tester
)。
我无法弹出第二个窗口;我尝试使用 dispose 它关闭程序但不运行主程序到最后。
主要的:
public static void main(String[] args){
LoginGui loginGuiWindow = null;
DeveloperGui devGui = null;
TesterGui tesGui = null;
UserCntrl uc = new UserCntrl();
try {
loginGuiWindow = new LoginGui(uc);
} catch (Exception e) {
e.printStackTrace();
}
System.out.print("Checking instance of: ");
if(loginGuiWindow.loggingResult > 0){
System.out.print("Checking instance of: ");
if (uc.user instanceof Developer) {
System.out.println("is instanceOf developer");
devGui = new DeveloperGui(uc);
}
if (uc.user instanceof Tester ) {
System.out.println("is instanceOf tester");
tesGui = new TesterGui(uc);
}
}
}
登录界面:
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int res;
String nick = textUser.getText();
String pass = textPassword.getText();
if((res = uc.handleLogin(nick, pass)) > 0){
loggingResult = res;
uc.handleUi(res);
frame.setVisible(false);
frame.dispose();
}
else{
JOptionPane.showMessageDialog(frame,
"Wrong username or password.",
"Logging error",
JOptionPane.PLAIN_MESSAGE);
}
}
});