login form in awt java

Solutions on MaxInterview for login form in awt java by the best coders in the world

showing results for - "login form in awt java"
Eleonora
29 Jun 2019
1package APDemo;
2import java.applet.Applet;
3import java.awt.Button;
4import java.awt.Color;
5import java.awt.Label;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import javax.swing.JOptionPane;
9import javax.swing.JPasswordField;
10import javax.swing.JTextField;
11 
12public class LoginPage extends Applet {
13 
14    Label userNameLabel, passwordLabel;
15    JTextField userName;
16    JPasswordField password;
17 
18    public void init() {
19 
20        userNameLabel = new Label("User Name");
21        userName = new JTextField(20);
22        userName.setText("User Name");
23        passwordLabel = new Label("Password");
24        password = new JPasswordField(20);
25        password.setText("Password");
26        password.setEchoChar('#');
27        login = new Button("Login");
28        reset = new Button("Reset");
29        userNameLabel.setBounds(10, 10, 100, 20);
30        userName.setBounds(150, 10, 150, 20);
31        passwordLabel.setBounds(10, 50, 100, 20);
32        password.setBounds(150, 50, 150, 20);
33        login.setBounds(50, 100, 100, 20);
34        login.setBackground(Color.GREEN);
35        reset.setBounds(200, 100, 100, 20);
36        reset.setBackground(Color.CYAN);
37        //set applet layout to null
38        setLayout(null);
39        //add elements to applet
40        add(userNameLabel);
41        add(userName);
42        add(passwordLabel);
43        add(password);
44        add(login);
45        add(reset);
46 
47        //set size of applet
48        setSize(400, 300);
49 
50        //login button click
51        login.addActionListener(new ActionListener() {
52 
53            @Override
54            public void actionPerformed(ActionEvent ae) {
55                String uname = userName.getText().toString();
56                String passwd = password.getText().toString();
57                System.out.println("User Name :" + uname);
58                System.out.println("Password :" + passwd);
59                if (uname.equals("Bond007") && passwd.equals("James007")) {
60                    JOptionPane.showMessageDialog(null, "Successfully Login");
61                } else {
62                    JOptionPane.showMessageDialog(null, "Opps username/ password is incorrect");
63                }
64 
65            }
66        });
67        //reset button click
68        reset.addActionListener(new ActionListener() {
69 
70            @Override
71            public void actionPerformed(ActionEvent ae) {
72                userName.setText("");
73                password.setText("");
74 
75            }
76        });
77 
78    }
79}
80