R.practical 12th
R.practical 12th
Practical No. 12: Write A Program To Demonstrate The Use Of Jtextfield And Jpasswordfield Using
Listener Interface..
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________
X - PROGRAM CODE
Q ------------------------
------------------------------------------- PROGRAM CODE -----------------------------------------------------------
import javax.swing.*;
import java.awt.*;
public class P12XCode extends JPasswordField
{
public P12XCode(int columns)
{
super(columns);
}
@Override
public char getEchoChar()
{
return '#';
}
public static void main(String[] args)
{
JFrame f = new JFrame("To Set The Password Character As '#' instead of
'*' ");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(new FlowLayout());
P12XCode pf = new P12XCode(20);
pf.setEchoChar('#');
JButton PB = new JButton("Show Password");
PB.addActionListener(e ->
{
char echoChar = pf.getEchoChar();
if (echoChar == 0)
{
pf.setEchoChar('#');
}
else
{
pf.setEchoChar((char) 0);
}
});
JButton B1 = new JButton("Hide Password");
B1.addActionListener(e ->
{
char echoChar = pf.getEchoChar();
if (echoChar == -1)
{
pf.setEchoChar((char) 0);
}
Subject - AJP [22517]
Practical No. 12: Write A Program To Demonstrate The Use Of Jtextfield And Jpasswordfield Using
Listener Interface..
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________
else
{
pf.setEchoChar('#');
}
});
f.add(pf);
f.add(PB);
f.add(B1);
f.pack();
f.setVisible(true);
f.setSize(500, 200);
}
}
XIII. Exercise
Q1 ------------------------
------------------------------------------- PROGRAM CODE -----------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
logP.add(pL);
logP.add(pf);
logP.add(logb);
f.add(logP, BorderLayout.CENTER);
f.setSize(300, 200);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
private static boolean isValidUser(String username, String password)
{
return username.equals(VALID_USERNAME) &&
password.equals(VALID_PASSWORD);
}
}
Q2 ------------------------
------------------------------------------- PROGRAM CODE -----------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
f.setSize(400, 150);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
-------------------------------------------- PROGRAM OUTPUT --------------------------------------------------
Subject - AJP [22517]
Practical No. 12: Write A Program To Demonstrate The Use Of Jtextfield And Jpasswordfield Using
Listener Interface..
Performed By – Vedant Nawade
CO5I – 44
_________________________________________________________________________________________________________________________________
Q3 ------------------------
------------------------------------------- PROGRAM CODE -----------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
f.setSize(300, 200);
}
}