怎么样实现密码登陆的样式 *
/**
* @(#)MyTest.java
*
*
* @author if
* @version 1.00 2007/3/24
*/
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
public class MyTest extends JFrame{
public MyTest() {
setTitle("password");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPasswordField jpf=new JPasswordField();
jpf.setEchoChar('*');
JButton jbutton=new JButton();
jbutton.setText("show password");
jbutton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
char[] pass=jpf.getPassword();
String value=new String(pass);
JOptionPane.showMessageDialog(null,value);
}
});
getContentPane().add(jpf,BorderLayout.NORTH);
getContentPane().add(jbutton,BorderLayout.CENTER);
pack();
}
public static void main(String[] args) {
MyTest frame=new MyTest();
frame.setVisible(true);
}
}