0

我有一个登录表单,它是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);
            }
        }
    }
}
4

1 回答 1

2

只是改变

public void Login()

public Login()

Login不是方法,而是构造函数。

于 2013-05-21T13:04:00.523 回答