Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Login extends JFrame implements ActionListener
- {
- private JTextField user;
- private JPasswordField pass;
- private JButton login;
- private JLabel lblstat;
- public static void main(String[] args)
- {
- Login frame = new Login();
- frame.setTitle("Login");
- frame.setVisible(true);
- frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
- frame.setResizable(true);
- frame.pack();
- }
- public Login()
- {
- JPanel p = new JPanel();
- p.setLayout(new GridLayout(4,2,5,5));
- p.setBorder(BorderFactory.createTitledBorder(""));
- JLabel lbluser = new JLabel("UserID: ");
- JLabel lblpass = new JLabel("Password: ");
- user = new JTextField();
- pass = new JPasswordField();
- login = new JButton("Login");
- login.addActionListener(this);
- JLabel space = new JLabel("");
- JLabel lblauth = new JLabel("Authorization: ");
- lblstat = new JLabel("");
- p.add(lbluser);
- p.add(user);
- p.add(lblpass);
- p.add(pass);
- p.add(space);
- p.add(login);
- p.add(lblauth);
- p.add(lblstat);
- add(p);
- }
- public void actionPerformed(ActionEvent e)
- {
- if(e.getSource() == login)
- {
- String User = "userid";
- char[] Pass = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
- char[] input = pass.getPassword();
- if(Pass.length == input.length && user.getText().equals(User))
- {
- lblstat.setForeground(Color.GREEN);
- lblstat.setText("Successful");
- Next next = new Next();
- next.setVisible(true);
- }
- else
- {
- lblstat.setForeground(Color.RED);
- lblstat.setText("Failed");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement