我有一个登录表单,它是JDialog
类的一个实例。但它不会出现在JFrame
. 我将它Application
作为一种方法在之前的内部实现并且它有效。但是在将它包装在Login
类中之后它不起作用也没有任何错误。问题是什么?
public class Application extends JFrame {
JDialog loginForm = null;
public Application() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setMinimumSize(new Dimension(800, 400));
setVisible(true);
loginForm = (JDialog) new Login();
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.alee.laf.WebLookAndFeel");
WebLookAndFeel.setDecorateDialogs(true);
} catch (Exception e) {
}
Application app = new Application();
}
}
public class Login extends JDialog {
private JButton loginButton = null;
private JButton cancelButton = null;
private JTextField userNameField = null;
private JPasswordField userPassField = null;
public void Login() {
//...
//...
setSize(new Dimension(300, 200));
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setTitle("Login");
setVisible(true);
setAlwaysOnTop(true);
}
class EventHandler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == loginButton) {
String username = userNameField.getText();
String password = Security.getSha256(userPassField.getText());
if(User.login(username, password)) {
// Login Successful
} else {
// Login Failed. Alert error
}
} else if(e.getSource() == cancelButton) {
System.exit(0);
}
}
}
}