Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public LoginDialog(JFrame parent){
- succeeded = false;
- lbUsername = new JLabel("Username");
- tfUsername = new JTextField(10);
- lbPassword = new JLabel("Password");
- pfPassword = new JPasswordField(10);
- btnLogin = new JButton("Login");
- btnCancel = new JButton("Cancel");
- panel = new JPanel();
- this.getContentPane().add(panel);
- this.setSize(new Dimension(210, 130));
- this.setResizable(false);
- this.setTitle("Login");
- this.setLocationRelativeTo(null);
- btnLogin.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- succeeded = Login.authenticate(getUsername(), getPassword());
- String text;
- if (succeeded)
- text = "Hi " + getUsername() + ", you've successfully logged in.";
- else
- text = "Wrong username and/or password.";
- JFrame response = new JFrame("Attention");
- JPanel okpanel = new JPanel();
- JLabel label = new JLabel(text);
- JButton okbtn = new JButton("OK");
- response.getContentPane().add(okpanel);
- okpanel.add(label);
- okpanel.add(okbtn);
- okbtn.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- // TODO Auto-generated method stub
- response.dispose();
- if (succeeded) {
- }
- }
- }
- );
- response.setSize(new Dimension(250,100));
- response.setVisible(true);
- response.setLocationRelativeTo(null);
- }
- }
- );
- panel.add(lbUsername);
- panel.add(tfUsername);
- panel.add(lbPassword);
- panel.add(pfPassword);
- panel.add(btnLogin);
- panel.add(btnCancel);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement