Advertisement
Guest User

Untitled

a guest
May 14th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class Login extends JFrame implements ActionListener
  6. {
  7. private JTextField user;
  8.  
  9. private JPasswordField pass;
  10.  
  11. private JButton login;
  12.  
  13. private JLabel lblstat;
  14.  
  15. public static void main(String[] args)
  16. {
  17. Login frame = new Login();
  18.  
  19. frame.setTitle("Login");
  20. frame.setVisible(true);
  21. frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
  22. frame.setResizable(true);
  23. frame.pack();
  24. }
  25.  
  26. public Login()
  27. {
  28. JPanel p = new JPanel();
  29.  
  30. p.setLayout(new GridLayout(4,2,5,5));
  31. p.setBorder(BorderFactory.createTitledBorder(""));
  32.  
  33. JLabel lbluser = new JLabel("UserID: ");
  34. JLabel lblpass = new JLabel("Password: ");
  35.  
  36. user = new JTextField();
  37.  
  38. pass = new JPasswordField();
  39.  
  40. login = new JButton("Login");
  41. login.addActionListener(this);
  42.  
  43. JLabel space = new JLabel("");
  44.  
  45. JLabel lblauth = new JLabel("Authorization: ");
  46. lblstat = new JLabel("");
  47.  
  48. p.add(lbluser);
  49. p.add(user);
  50. p.add(lblpass);
  51. p.add(pass);
  52. p.add(space);
  53. p.add(login);
  54. p.add(lblauth);
  55. p.add(lblstat);
  56.  
  57. add(p);
  58. }
  59.  
  60. public void actionPerformed(ActionEvent e)
  61. {
  62. if(e.getSource() == login)
  63. {
  64. String User = "userid";
  65.  
  66. char[] Pass = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
  67. char[] input = pass.getPassword();
  68.  
  69. if(Pass.length == input.length && user.getText().equals(User))
  70. {
  71. lblstat.setForeground(Color.GREEN);
  72. lblstat.setText("Successful");
  73. Next next = new Next();
  74.     next.setVisible(true);
  75. }
  76. else
  77. {
  78. lblstat.setForeground(Color.RED);
  79. lblstat.setText("Failed");
  80. }
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement