Creating a Login screen using Java AWT source code: This simple AWT program in java is used to design a login form & performs the login functions in a separate window. In this Java tutorial, there will be 2 types of users. They are valid user and invalid user. If the user name and password details are correct, that user will be consider as a valid user. If the login conditionals are wrong, that user will be considered as an invalid user. Example code is given below.
LOGIN WINDOW IN JAVA AWT
This java AWT program is used to create a login screen for many places like windows login, email login, folder login by matching the user name and password with per-entered user name and password. If it is correct, proceed further else user will be rejected.
[Useful: C Programming Guide] & [IT Companies List]
Java AWT login program:
Q: Write a Java code for login process using of AWT.
//Import statements import java.awt.*; import java.awt.event.*; //Class definition class LoginWindow extends Frame implements ActionListener { //Variable declaration TextField te1, te2; Label la1, la2; Button bu1, bu2; public LoginWindow(String title) { super(title); // © http://students3k.com – Karthikh Venkat //creating components te1=new TextField(10); te2=new TextField(10); te2.setEchoChar('*'); la1=new Label("User ID: "); la2=new Label("Password : "); bu1=new Button("OK"); bu2=new Button("CANCEL"); //register the buttons with action listener bu1.addActionListener(this); bu2.addActionListener(this); //set the layout manager setLayout(new FlowLayout()); // © http://students3k.com – Karthikh Venkat //add the components to the frame add(la1); add(te1); add(la2); add(te2; add(bu1); add(bu2); setSize(200,200); show(); } public void actionPerformed(ActionEvent e) { if(e.getSource()==bu1) { if(te1.getText().equals("vision") && te2.getText().equals("nrt")) setTitle("Login Form - Valid user"); else setTitle("Login Form - Invalid user"); } else System.exit(0); } // © http://students3k.com – Karthikh Venkat public static void main(String args[]) { new LoginWindow("User Login"); } }