Advertisement
Guest User

Untitled

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