Reputation:
I have a login form which is an instance of JDialog
class. but it doesn't appear inside the JFrame
. I implemented it inside the Application
before as a method and it worked. but after wrapping it inside the Login
class it does not work also there is not any error. what is the problem?
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);
}
}
}
}
Upvotes: 0
Views: 132
Reputation: 22243
Just change
public void Login()
to
public Login()
Login
is not a method, it is a constructor.
Upvotes: 1