Simple Login Form in java Using AWT

in java •  4 years ago 

import java.applet.Applet;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPasswordField;

import sun.security.util.Password;

public class login extends Applet
{
Label title = new Label("Login Page");
Label username = new Label("Username");
Label password = new Label("Password");
TextField tusername = new TextField(20);
TextField tpassword = new TextField(10);
Button login = new Button("Login");
Button reset = new Button("Reset");

public void init()
{
String p = "*";
setSize(500, 500);
setLayout(null);
//Setting Bounds
title.setBounds(150, 50, 200, 100);
username.setBounds(20, 150, 150, 100);
password.setBounds(20, 240, 150, 100);
tusername.setBounds(180, 180, 250, 40);
tpassword.setBounds(180, 270, 250, 40);
login.setBounds(100, 350, 100, 40);
reset.setBounds(250, 350, 100, 40);

 //Setting Fonts
 title.setFont(new Font("Lucida",Font.PLAIN,34));
 username.setFont(new Font("Lucida",Font.PLAIN,24));
 tusername.setFont(new Font("Lucida",Font.PLAIN,24));
 username.setFont(new Font("Lucida",Font.PLAIN,24));
 password.setFont(new Font("Lucida",Font.PLAIN,24));
 

 
 tpassword.setEchoChar('*');


 add(username);
 add(title);
 add(password);
 add(tusername);
 add(tpassword);
 add(login);
 add(reset);
 setVisible(true);
 
 login.addActionListener(new ActionListener() {
    
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        String user =  username.getText().toString();
        String pass = password.getText().toString();
        if(user=="Sanket" && pass == "Sanket@123")
        {
            //you can write your action code here like what is done after clicking the login button
        }
        
    }
});

}
}

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!