You are on page 1of 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