0% found this document useful (0 votes)
56 views6 pages

Page No. 65 (Write)

This document contains code for 3 Java programs that create graphical user interfaces (GUIs) for password entry and validation. The first program creates a basic password field GUI that allows a user to enter a password without echoing the text. The second program enhances this by adding a username field, submit button, and label to provide authentication feedback. It checks the entered password against a hardcoded value. The third program further validates the password by checking its length and displaying both the username and password if valid, otherwise providing error feedback.

Uploaded by

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

Page No. 65 (Write)

This document contains code for 3 Java programs that create graphical user interfaces (GUIs) for password entry and validation. The first program creates a basic password field GUI that allows a user to enter a password without echoing the text. The second program enhances this by adding a username field, submit button, and label to provide authentication feedback. It checks the entered password against a hardcoded value. The third program further validates the password by checking its length and displaying both the username and password if valid, otherwise providing error feedback.

Uploaded by

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

EXPERIMENT NO.

12

PAGE NO.=65 (WRITE)

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class jtxt1 extends JFrame
{
JPasswordField t1;
JLabel l1;
String msg;
jtxt1()
{
setSize(300,300);
setVisible(true);
setLayout(new BorderLayout());
JLabel l1=new JLabel("Enter Password ");
JPasswordField t1=new JPasswordField();
t1.setEchoChar('#');
JLabel l2=new JLabel("Text Not Changed");
add(l1,BorderLayout.NORTH);
add(t1,BorderLayout.CENTER);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args)
{ jtxt1 t=new jtxt1();
}
}
EXERCISE –PROGRAM-1 (WRITE) (Page no.66)

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class jtxt2 extends JFrame implements ActionListener
{
JPasswordField t2;
JTextField t1;
JLabel l1,l2,l3;
JButton b;
String msg;
jtxt2()
{
setSize(300,300);
setVisible(true);
setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
l1=new JLabel("Enter Username : ");
t1=new JTextField(20);
l2=new JLabel("Enter Password : ");
t2=new JPasswordField(20);
t2.setEchoChar('#');
b=new JButton("SUBMIT");
b.addActionListener(this);
l3=new JLabel("");
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(b);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{ String s=new String(t2.getPassword());
if(s.equals("ADMIN")==true)
{
l3.setText("Authentication Successful Welcome "+t1.getText());
}else
{
l3.setText("Authentication Failed");
}
}
public static void main(String[] args)
{ jtxt2 t=new jtxt2();
}
}
PROGRAM-3(Print) (Page No.66)
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class jtxt4 extends JFrame implements ActionListener
{
JPasswordField t2;
JTextField t1;
JLabel l1,l2,l3;
JButton b;
String msg;
jtxt4()
{
setSize(300,300);
setVisible(true);
setLayout(new FlowLayout(FlowLayout.CENTER,20,20));
l1=new JLabel("Enter Username : ");
t1=new JTextField(20);
l2=new JLabel("Enter Password : ");
t2=new JPasswordField(20);
t2.setEchoChar('$');
b=new JButton("SUBMIT");
b.addActionListener(this);
l3=new JLabel("");
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(b);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public void actionPerformed(ActionEvent e)


{ String s=new String(t2.getPassword());
if(s.length()<6)
{
l3.setText("Password length is less than 6 characters");
t2.setText("");
}else
{
l3.setText("User = "+t1.getText()+" Password = "+s);
}
}
public static void main(String[] args)
{
jtxt4 t=new jtxt4();
}

You might also like