17 Sept 2012

Set Password Symbol example in java


import javax.swing.JPasswordField;  
import javax.swing.JFrame;  
  
import java.awt.FlowLayout;  
  
public class SetPasswordSymbol  
{  
public static void main(String[]args)  
{  
 //Create a password field with number of columns equal to 10  
 JPasswordField passwordField=new JPasswordField(10);  
  
 //Set password symbol  
 //In my case i use *  
 //You can change for what you want.But make sure it is only one character  
 //This is because, method setEchoChar receive only one character  
 passwordField.setEchoChar('*');  
  
  
 //Create a JFrame with title ( Set Password Symbol )  
 JFrame frame=new JFrame("Set Password Symbol");  
  
 //Set JFrame layout to FlowLayout  
 frame.setLayout(new FlowLayout());  
  
 //Add password field into JFrame  
 frame.add(passwordField);  
  
 //Set default close operation for JFrame  
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  
 //Set JFrame size to :  
 //WIDTH : 300 pixels  
 //HEIGHT : 65 pixels  
 frame.setSize(300,65);  
  
 //Make JFrame visible. So we can see it  
 frame.setVisible(true);  
}  
}  

0 comments:

Post a Comment