The PasswordField is a special kind of textfield. It is a single line textfield used for accepting passwords without displaying the characters typed in. Each typed character is represented by an echo character typically an astriek (*). To create a PasswordField component, instantiate the JpasswordField class.
import javax.swing.*;
import java.awt.* ;
class JPasswordFieldExample extends JFrame
{
JPasswordFieldExample()
{
setLayout(new FlowLayout());
JLabel lblUserid = new JLabel("Userid");
JTextField txtUserid = new JTextField("Mr Thakur",15);
JLabel lblpassword = new JLabel("password");
JPasswordField txtpassword = new JPasswordField(15);
add(lblUserid); add(txtUserid);
add(lblpassword); add(txtpassword);
}
}
class JPasswordFieldJavaExample
{
public static void main(String args[])
{
JPasswordFieldExample frame = new JPasswordFieldExample();
frame.setTitle("JPasswordField in Java Swing Example");
frame.setBounds(200,250,250,150);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}