Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package login;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import java.awt.event.ActionListener;
- import java.util.HashMap;
- import java.awt.event.ActionEvent;
- import javax.swing.JPasswordField;
- import java.awt.Color;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class LoginWindow {
- private JFrame frmLoginWindow;
- private JTextField userName;
- private JTextField password;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- LoginWindow window = new LoginWindow();
- window.frmLoginWindow.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public LoginWindow() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frmLoginWindow = new JFrame();
- frmLoginWindow.getContentPane().setBackground(Color.LIGHT_GRAY);
- frmLoginWindow.setResizable(false);
- frmLoginWindow.setTitle("Login Window");
- frmLoginWindow.setBounds(100, 100, 342, 188);
- frmLoginWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frmLoginWindow.getContentPane().setLayout(null);
- JLabel lblUserName = new JLabel("User name:");
- lblUserName.setBounds(28, 27, 97, 14);
- frmLoginWindow.getContentPane().add(lblUserName);
- JLabel lblPassword = new JLabel("Password:");
- lblPassword.setBounds(28, 54, 97, 14);
- frmLoginWindow.getContentPane().add(lblPassword);
- userName = new JTextField();
- userName.setBounds(101, 25, 187, 17);
- frmLoginWindow.getContentPane().add(userName);
- userName.setColumns(10);
- JButton btnLogIn = new JButton("Log in ");
- btnLogIn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String usrn = userName.getText();
- String pswr = password.getText();
- if(UserMap.findInMap(usrn) && UserMap.checkPassword(usrn,pswr))
- frmLoginWindow.getContentPane().setBackground(Color.GREEN);
- else if(UserMap.findInMap(usrn) || UserMap.checkPassword(usrn,pswr))
- frmLoginWindow.getContentPane().setBackground(Color.YELLOW);
- else if(!(UserMap.findInMap(usrn) && UserMap.checkPassword(usrn,pswr)))
- frmLoginWindow.getContentPane().setBackground(Color.RED);
- }
- });
- btnLogIn.setBounds(118, 115, 89, 23);
- frmLoginWindow.getContentPane().add(btnLogIn);
- JButton btnOut = new JButton("Out");
- btnOut.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- btnOut.setBounds(216, 115, 89, 23);
- frmLoginWindow.getContentPane().add(btnOut);
- JCheckBox chckbxRememberMe = new JCheckBox("Remember me ");
- chckbxRememberMe.setBackground(Color.LIGHT_GRAY);
- chckbxRememberMe.setBounds(28, 85, 277, 23);
- frmLoginWindow.getContentPane().add(chckbxRememberMe);
- password = new JTextField();
- password.setBounds(101, 52, 187, 17);
- frmLoginWindow.getContentPane().add(password);
- password.setColumns(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement