Guest User

Untitled

a guest
Feb 7th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3. import javax.swing.JButton;
  4. import javax.swing.JFrame;
  5. import javax.swing.JLabel;
  6. import javax.swing.JOptionPane;
  7. import javax.swing.JPanel;
  8. import javax.swing.JPasswordField;
  9. import javax.swing.JTextField;
  10.  
  11. public class Login {
  12.  
  13. public static JFrame frame = new JFrame("Login System V.01");
  14. public static JPanel panel = new JPanel();
  15. public static JLabel username_label = new JLabel("Username:");
  16. public static JLabel password_label = new JLabel("Password:");
  17. public static JButton login_button = new JButton("Login");
  18. public static JTextField username_textfield = new JTextField();
  19. public static JPasswordField password_field = new JPasswordField(10);
  20.  
  21.  
  22. public static void main(String [] args) {
  23. Login_Interface();
  24. }
  25.  
  26. public static void Login_Interface() {
  27.  
  28. frame.add(panel);
  29. panel.setSize(200,200);
  30. panel.setLayout(null);
  31. panel.add(login_button);
  32. login_button.setBounds(80,115,50,35);
  33. panel.add(username_label);
  34. username_label.setBounds(20,30,70,70);
  35. panel.add(password_label);
  36. password_label.setBounds(20,60,70,70);
  37. panel.add(username_textfield);
  38. username_textfield.setBounds(90, 56, 60, 20);
  39. panel.add(password_field);
  40. password_field.setBounds(90, 85, 60, 20);
  41. frame.setSize(200, 200);
  42. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  43. frame.setVisible(true);
  44. frame.setLocationRelativeTo(null);
  45. panel.setVisible(true);
  46. login_button.addActionListener(new ActionListener() {
  47.  
  48.  
  49. public void actionPerformed(ActionEvent e) {
  50. String user_name = username_textfield.getText();
  51. String pass_word = password_field.getText();
  52. login_system(user_name,pass_word);
  53.  
  54. }
  55.  
  56. });
  57.  
  58. }
  59.  
  60. public static void login_system(String user, String pass) {
  61.  
  62. if((user.equalsIgnoreCase("Alex")) && pass.equalsIgnoreCase("admin")) {
  63. JOptionPane.showMessageDialog(null, "Logged in succesfully!");
  64. AdminLogin();
  65. frame.setVisible(false);
  66. } else {
  67. JOptionPane.showMessageDialog(null, "Wrong Username/Password!");
  68. }
  69. }
  70. public static void AdminLogin() {
  71. JFrame admin_frame = new JFrame("Admin Menu");
  72. JPanel admin_panel = new JPanel();
  73. JLabel admin_Label_1 = new JLabel();
  74. admin_frame.setLocationRelativeTo(null);
  75. admin_frame.add(admin_panel);
  76. admin_panel.add(admin_Label_1);
  77. admin_frame.setVisible(true);
  78. admin_frame.setResizable(false);
  79. admin_frame.setSize(200, 200);
  80. admin_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  81. }
  82. }
Add Comment
Please, Sign In to add comment