Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. package login;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JTextField;
  8. import javax.swing.JButton;
  9. import javax.swing.JCheckBox;
  10. import java.awt.event.ActionListener;
  11. import java.util.HashMap;
  12. import java.awt.event.ActionEvent;
  13. import javax.swing.JPasswordField;
  14. import java.awt.Color;
  15. import java.awt.event.MouseAdapter;
  16. import java.awt.event.MouseEvent;
  17.  
  18. public class LoginWindow {
  19.  
  20. private JFrame frmLoginWindow;
  21. private JTextField userName;
  22. private JTextField password;
  23.  
  24. /**
  25. * Launch the application.
  26. */
  27. public static void main(String[] args) {
  28. EventQueue.invokeLater(new Runnable() {
  29. public void run() {
  30. try {
  31. LoginWindow window = new LoginWindow();
  32. window.frmLoginWindow.setVisible(true);
  33. } catch (Exception e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. });
  38. }
  39.  
  40. /**
  41. * Create the application.
  42. */
  43. public LoginWindow() {
  44. initialize();
  45. }
  46.  
  47. /**
  48. * Initialize the contents of the frame.
  49. */
  50. private void initialize() {
  51. frmLoginWindow = new JFrame();
  52. frmLoginWindow.getContentPane().setBackground(Color.LIGHT_GRAY);
  53. frmLoginWindow.setResizable(false);
  54. frmLoginWindow.setTitle("Login Window");
  55. frmLoginWindow.setBounds(100, 100, 342, 188);
  56. frmLoginWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57. frmLoginWindow.getContentPane().setLayout(null);
  58.  
  59. JLabel lblUserName = new JLabel("User name:");
  60. lblUserName.setBounds(28, 27, 97, 14);
  61. frmLoginWindow.getContentPane().add(lblUserName);
  62.  
  63. JLabel lblPassword = new JLabel("Password:");
  64. lblPassword.setBounds(28, 54, 97, 14);
  65. frmLoginWindow.getContentPane().add(lblPassword);
  66.  
  67. userName = new JTextField();
  68. userName.setBounds(101, 25, 187, 17);
  69. frmLoginWindow.getContentPane().add(userName);
  70. userName.setColumns(10);
  71.  
  72. JButton btnLogIn = new JButton("Log in ");
  73. btnLogIn.addActionListener(new ActionListener() {
  74. public void actionPerformed(ActionEvent e) {
  75. String usrn = userName.getText();
  76. String pswr = password.getText();
  77. if(UserMap.findInMap(usrn) && UserMap.checkPassword(usrn,pswr))
  78. frmLoginWindow.getContentPane().setBackground(Color.GREEN);
  79.  
  80. else if(UserMap.findInMap(usrn) || UserMap.checkPassword(usrn,pswr))
  81. frmLoginWindow.getContentPane().setBackground(Color.YELLOW);
  82.  
  83. else if(!(UserMap.findInMap(usrn) && UserMap.checkPassword(usrn,pswr)))
  84. frmLoginWindow.getContentPane().setBackground(Color.RED);
  85. }
  86. });
  87.  
  88. btnLogIn.setBounds(118, 115, 89, 23);
  89. frmLoginWindow.getContentPane().add(btnLogIn);
  90.  
  91. JButton btnOut = new JButton("Out");
  92. btnOut.addActionListener(new ActionListener() {
  93. public void actionPerformed(ActionEvent e) {
  94. System.exit(0);
  95. }
  96. });
  97. btnOut.setBounds(216, 115, 89, 23);
  98. frmLoginWindow.getContentPane().add(btnOut);
  99.  
  100. JCheckBox chckbxRememberMe = new JCheckBox("Remember me ");
  101. chckbxRememberMe.setBackground(Color.LIGHT_GRAY);
  102. chckbxRememberMe.setBounds(28, 85, 277, 23);
  103. frmLoginWindow.getContentPane().add(chckbxRememberMe);
  104.  
  105. password = new JTextField();
  106. password.setBounds(101, 52, 187, 17);
  107. frmLoginWindow.getContentPane().add(password);
  108. password.setColumns(10);
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement