Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Login implements ActionListener {
- String usernameVar;
- String passwordVar;
- JFrame frame = new JFrame();
- JPanel loginScreen = new JPanel();
- JLabel username = new JLabel("Username: ");
- JLabel password = new JLabel("Password");
- JTextField passwordIn = new JTextField();
- JTextField usernameIn = new JTextField();
- JButton loginButton = new JButton("Login");
- JButton subButton = new JButton("Create new account");
- Font font = new Font("", Font.PLAIN, 20);
- Font answers = new Font("", Font.PLAIN, 16);
- public Login() {
- frame.setSize(700, 500);
- frame.setResizable(false);
- frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
- username.setSize(200, 100);
- username.setLocation(200, 50);
- username.setFont(font);
- usernameIn.setSize(200, 20);
- usernameIn.setLocation(320, 95);
- usernameIn.setFont(answers);
- password.setSize(200, 100);
- password.setLocation(200, 150);
- password.setFont(font);
- passwordIn.setSize(200, 20);
- passwordIn.setLocation(320, 195);
- passwordIn.setFont(answers);
- loginButton.setSize(100, 40);
- loginButton.setLocation(200, 300);
- loginButton.setFont(font);
- loginButton.addActionListener(this);
- subButton.setSize(250, 40);
- subButton.setLocation(350, 300);
- subButton.setFont(font);
- subButton.addActionListener(this);
- loginScreen.setLayout(null);
- loginScreen.add(username);
- loginScreen.add(password);
- loginScreen.add(usernameIn);
- loginScreen.add(passwordIn);
- loginScreen.add(loginButton);
- loginScreen.add(subButton);
- frame.add(loginScreen);
- frame.setVisible(true);
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == loginButton) {
- if (usernameIn.getText().equals(usernameVar) && passwordIn.getText().equals(passwordVar)) {
- loginScreen.setVisible(false);
- frame.add(Logged.loggedScreen);
- Logged.loggedScreen.setVisible(true);
- }
- }
- if (e.getSource() == subButton) {
- loginScreen.setVisible(false);
- frame.add(Create.subScreen);
- Create.subScreen.setVisible(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement