Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- public class Login {
- public static JFrame frame = new JFrame("Login System V.01");
- public static JPanel panel = new JPanel();
- public static JLabel username_label = new JLabel("Username:");
- public static JLabel password_label = new JLabel("Password:");
- public static JButton login_button = new JButton("Login");
- public static JTextField username_textfield = new JTextField();
- public static JPasswordField password_field = new JPasswordField(10);
- public static void main(String [] args) {
- Login_Interface();
- }
- public static void Login_Interface() {
- frame.add(panel);
- panel.setSize(200,200);
- panel.setLayout(null);
- panel.add(login_button);
- login_button.setBounds(80,115,50,35);
- panel.add(username_label);
- username_label.setBounds(20,30,70,70);
- panel.add(password_label);
- password_label.setBounds(20,60,70,70);
- panel.add(username_textfield);
- username_textfield.setBounds(90, 56, 60, 20);
- panel.add(password_field);
- password_field.setBounds(90, 85, 60, 20);
- frame.setSize(200, 200);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- frame.setLocationRelativeTo(null);
- panel.setVisible(true);
- login_button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String user_name = username_textfield.getText();
- String pass_word = password_field.getText();
- login_system(user_name,pass_word);
- }
- });
- }
- public static void login_system(String user, String pass) {
- if((user.equalsIgnoreCase("Alex")) && pass.equalsIgnoreCase("admin")) {
- JOptionPane.showMessageDialog(null, "Logged in succesfully!");
- AdminLogin();
- frame.setVisible(false);
- } else {
- JOptionPane.showMessageDialog(null, "Wrong Username/Password!");
- }
- }
- public static void AdminLogin() {
- JFrame admin_frame = new JFrame("Admin Menu");
- JPanel admin_panel = new JPanel();
- JLabel admin_Label_1 = new JLabel();
- admin_frame.setLocationRelativeTo(null);
- admin_frame.add(admin_panel);
- admin_panel.add(admin_Label_1);
- admin_frame.setVisible(true);
- admin_frame.setResizable(false);
- admin_frame.setSize(200, 200);
- admin_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Add Comment
Please, Sign In to add comment