0% found this document useful (0 votes)
8 views2 pages

PracticalNo12 1

Uploaded by

Ashish Mavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

PracticalNo12 1

Uploaded by

Ashish Mavani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No.

: 12

Practical Name: Write a program to demonstrate the use of JTextField and JPasswordField using
Listener Interface.

Roll No.: 47

Student Name: Mavani Ashish Shantilal

Program:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class practical12_1 extends JFrame implements ActionListener


{
JLabel l1,l2,l3;
JTextField t1;
JPasswordField p1;
JButton b1;
practical12_1()
{
setTitle("User Authentication");
setVisible(true);
setSize(360,300);
setLayout(null);

l1 = new JLabel("Username: ");


l1.setBounds(80,80,80,25);
l2 = new JLabel("Password: ");
l2.setBounds(80,115,80,25);
t1 = new JTextField();
t1.setBounds(170,80,100,25);
p1 = new JPasswordField();
p1.setBounds(170,115,100,25);
b1 = new JButton("Login");
b1.setBounds(80,150,80,25);
l3 = new JLabel("");
l3.setBounds(80,185,300,25);

b1.addActionListener(this);
add(l1);
add(l2);
add(t1);
add(p1);
add(b1);
add(l3);
}
public void actionPerformed(ActionEvent ae)
{
String user = t1.getText();
String pass = new String(p1.getPassword());

if(user.equals("Ashish") && pass.equals("pass@123"))


{
l3.setText("Login Successful!");
}
else
{
l3.setText("Invalid Username or Password");
}
}
public static void main(String args[])
{
practical12_1 pr12_1 = new practical12_1();
}
}

Output:

You might also like