PasswordField Component in Java Swing


Simple code that explains how the JPasswordField component can be created in Java Swing.

File:pe.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class pe extends JFrame
{
JPasswordField p;
pe()
{
setTitle(“Password Text Box”);
JPanel content=new JPanel();

p=new JPasswordField(20);
p.setFont(new Font(“Arial”,Font.PLAIN,16));
content.add(p);
getContentPane().add(content);

myadapter my=new myadapter();
addWindowListener(my);
}
public class myadapter extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
public static void main(String ar[])
{
pe a=new pe();
a.setSize(400,400);
a.setVisible(true);
}
}

Output looks

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s