Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class Login extends JFrame {
- JPanel Panel;
- JLabel txtUser;
- JLabel txtPw;
- JLabel status;
- JTextField user;
- JPasswordField pw;
- JButton submit;
- String[][] users = {
- {"admin","1234"},
- {"unknown","666"}
- };
- private String user_name;
- private String user_pw;
- public Login() {
- setSize(290,150);
- setLocation(100,100);
- setTitle("Login");
- Panel = new JPanel();
- Panel.setLayout(null);
- Panel.setBackground(Color.decode("#C16262"));
- txtUser = new JLabel("User:");
- txtPw = new JLabel("Password:");
- status = new JLabel("");
- txtUser.setBounds(20,13,80,20);
- txtPw.setBounds(20,47,80,20);
- status.setBounds(20,110,300,20);
- status.setForeground(Color.pink);
- user = new JTextField(10);
- pw = new JPasswordField(10);
- user.setBounds(110,15,150,20);
- pw.setBounds(110,50,150,20);
- submit = new JButton("Submit");
- submit.setBounds(110,85,100,20);
- Panel.add(txtUser);
- Panel.add(txtPw);
- Panel.add(status);
- Panel.add(user);
- Panel.add(pw);
- Panel.add(submit);
- getContentPane().add(Panel);
- setVisible(true);
- submit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- user_name = user.getText().toLowerCase();
- user_pw = String.valueOf(pw.getPassword());
- if (user_name.length() > 3 && user_pw.length() > 2){
- boolean done = false;
- for(int i = 0;i<users.length;i++){
- if (user_name.equals(users[i][0]) && user_pw.equals(users[i][1])){
- done = true;
- break;
- }
- }
- if (done){
- new Bank();
- status.setText(null);
- }else{
- status.setText("Invalid Username / Password!");
- pw.setText(null);
- }
- }else{
- status.setText("Enter an existent Login / Password!");
- user.setText(null);
- pw.setText(null);
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement