Advertisement
Guest User

Untitled

a guest
Jan 26th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public LoginDialog(JFrame parent){
  2. succeeded = false;
  3. lbUsername = new JLabel("Username");
  4. tfUsername = new JTextField(10);
  5. lbPassword = new JLabel("Password");
  6. pfPassword = new JPasswordField(10);
  7. btnLogin = new JButton("Login");
  8. btnCancel = new JButton("Cancel");
  9. panel = new JPanel();
  10.  
  11. this.getContentPane().add(panel);
  12. this.setSize(new Dimension(210, 130));
  13. this.setResizable(false);
  14. this.setTitle("Login");
  15. this.setLocationRelativeTo(null);
  16.  
  17. btnLogin.addActionListener(
  18. new ActionListener() {
  19. @Override
  20. public void actionPerformed(ActionEvent e) {
  21. succeeded = Login.authenticate(getUsername(), getPassword());
  22. String text;
  23. if (succeeded)
  24. text = "Hi " + getUsername() + ", you've successfully logged in.";
  25. else
  26. text = "Wrong username and/or password.";
  27. JFrame response = new JFrame("Attention");
  28. JPanel okpanel = new JPanel();
  29. JLabel label = new JLabel(text);
  30. JButton okbtn = new JButton("OK");
  31.  
  32. response.getContentPane().add(okpanel);
  33. okpanel.add(label);
  34. okpanel.add(okbtn);
  35.  
  36. okbtn.addActionListener(
  37. new ActionListener() {
  38.  
  39. @Override
  40. public void actionPerformed(ActionEvent arg0) {
  41. // TODO Auto-generated method stub
  42. response.dispose();
  43. if (succeeded) {
  44.  
  45. }
  46. }
  47.  
  48. }
  49. );
  50.  
  51. response.setSize(new Dimension(250,100));
  52. response.setVisible(true);
  53. response.setLocationRelativeTo(null);
  54. }
  55. }
  56. );
  57.  
  58. panel.add(lbUsername);
  59. panel.add(tfUsername);
  60. panel.add(lbPassword);
  61. panel.add(pfPassword);
  62. panel.add(btnLogin);
  63. panel.add(btnCancel);
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement