Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. public class Login implements ActionListener {
  2.     String usernameVar;
  3.     String passwordVar;
  4.  
  5.     JFrame frame = new JFrame();
  6.     JPanel loginScreen = new JPanel();
  7.     JLabel username = new JLabel("Username: ");
  8.     JLabel password = new JLabel("Password");
  9.     JTextField passwordIn = new JTextField();
  10.     JTextField usernameIn = new JTextField();
  11.     JButton loginButton = new JButton("Login");
  12.     JButton subButton = new JButton("Create new account");
  13.     Font font = new Font("", Font.PLAIN, 20);
  14.     Font answers = new Font("", Font.PLAIN, 16);
  15.  
  16.     public Login() {
  17.         frame.setSize(700, 500);
  18.         frame.setResizable(false);
  19.         frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
  20.  
  21.         username.setSize(200, 100);
  22.         username.setLocation(200, 50);
  23.         username.setFont(font);
  24.  
  25.         usernameIn.setSize(200, 20);
  26.         usernameIn.setLocation(320, 95);
  27.         usernameIn.setFont(answers);
  28.  
  29.         password.setSize(200, 100);
  30.         password.setLocation(200, 150);
  31.         password.setFont(font);
  32.  
  33.         passwordIn.setSize(200, 20);
  34.         passwordIn.setLocation(320, 195);
  35.         passwordIn.setFont(answers);
  36.  
  37.         loginButton.setSize(100, 40);
  38.         loginButton.setLocation(200, 300);
  39.         loginButton.setFont(font);
  40.         loginButton.addActionListener(this);
  41.  
  42.         subButton.setSize(250, 40);
  43.         subButton.setLocation(350, 300);
  44.         subButton.setFont(font);
  45.         subButton.addActionListener(this);
  46.  
  47.         loginScreen.setLayout(null);
  48.         loginScreen.add(username);
  49.         loginScreen.add(password);
  50.         loginScreen.add(usernameIn);
  51.         loginScreen.add(passwordIn);
  52.         loginScreen.add(loginButton);
  53.         loginScreen.add(subButton);
  54.  
  55.         frame.add(loginScreen);
  56.         frame.setVisible(true);
  57.     }
  58.  
  59.     public void actionPerformed(ActionEvent e) {
  60.         if (e.getSource() == loginButton) {
  61.             if (usernameIn.getText().equals(usernameVar) && passwordIn.getText().equals(passwordVar)) {
  62.                 loginScreen.setVisible(false);
  63.                 frame.add(Logged.loggedScreen);
  64.                 Logged.loggedScreen.setVisible(true);
  65.             }
  66.         }
  67.         if (e.getSource() == subButton) {
  68.             loginScreen.setVisible(false);
  69.             frame.add(Create.subScreen);
  70.             Create.subScreen.setVisible(true);
  71.         }
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement