Aditi Java
Aditi Java
Code:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public Login() {
// Set title and frame properties
setTitle("Registration and login Form");
setSize(600, 500);
setLayout(null);
setVisible(true);
// Name
Name = new Label("Name:");
Name.setBounds(20, 50, 100, 30);
name = new TextField();
name.setBounds(160, 50, 150, 30);
// Address
Address = new Label("Address:");
Address.setBounds(20, 90, 100, 30);
address = new TextArea();
address.setBounds(160, 90, 150, 50);
// Gender
Gender = new Label("Gender:");
Gender.setBounds(20, 150, 100, 30);
CheckboxGroup obj = new CheckboxGroup();
male = new Checkbox("Male", obj, false);
male.setBounds(160, 150, 50, 30);
female = new Checkbox("Female", obj, false);
female.setBounds(220, 150, 60, 30);
other = new Checkbox("Other", obj, false);
other.setBounds(290, 150, 60, 30);
// Email
Email = new Label("Email:");
Email.setBounds(20, 190, 100, 30);
email = new TextField();
email.setBounds(160, 190, 150, 30);
// Username
Uname = new Label("Username:");
Uname.setBounds(20, 230, 100, 30);
uname = new TextField();
uname.setBounds(160, 230, 150, 30);
// Password
Pass = new Label("Password:");
Pass.setBounds(20, 270, 100, 30);
pass = new TextField();
pass.setBounds(160, 270, 150, 30);
// Hobbies
Hobby = new Label("Hobbies:");
Hobby.setBounds(20, 310, 100, 30);
hobby1 = new Checkbox("Reading");
hobby1.setBounds(160, 310, 70, 30);
hobby2 = new Checkbox("Coding");
hobby2.setBounds(240, 310, 70, 30);
hobby3 = new Checkbox("Writing");
hobby3.setBounds(320, 310, 70, 30);
hobby4 = new Checkbox("Sports");
hobby4.setBounds(400, 310, 70, 30);
hobby5 = new Checkbox("Music");
hobby5.setBounds(480, 310, 70, 30);
// Submit Button
b = new Button("Submit");
b.setBounds(160, 360, 80, 30);
b.addActionListener(this);
// Login Button
b1= new Button("Login");
b1.setBounds(700, 360, 80, 30);
b1.addActionListener(this);
// Validation Checks
if (enteredName.isEmpty() || enteredEmail.isEmpty() || enteredUsername.isEmpty() ||
enteredPassword.isEmpty() || enteredAddress.isEmpty())
{
message = "All fields are required!";
} else if (enteredPassword.length() < 6) {
message = "Password must be at least 6 characters!";
} else {
message = "Registration Successful!";
}
un.add(enteredUsername);
p.add(enteredPassword);
repaint(); // Refresh screen
}
if (e.getSource() == b1)
{
if(((un.size()<0)&&(p.size()<0)) && ((un.size()>4)&&(p.size()>4)))
message="Either no data is present or no of data have exceed";
else
{
for(int i=0;i<un.size();i++)
{
String u1=uname1.getText().trim();
String p1=pass1.getText().trim();
if ((u1.equals(un.get(i))) && (p1.equals(p.get(i))))
{message="all credentials are correct";break;}
else
message="Wrong credentail";
}//for closing
}
repaint();
}
}