java密码框明文显示密码

import javax.swing.*;
import java.awt.event.*;


public class TTTTTTT extends JFrame{
private JPasswordField passwordText;
JCheckBox checkBox;
public TTTTTTT() {
getContentPane().setLayout(null);

//密码框
passwordText = new JPasswordField();
passwordText.setBounds(95, 82, 204, 24);
getContentPane().add(passwordText);

//单选
checkBox = new JCheckBox("显示密码");
checkBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange()==ItemEvent.SELECTED){//被选中
passwordText.setEchoChar((char)0);
}else{
passwordText.setEchoChar('*');
}
}
});
checkBox.setBounds(299, 81, 133, 27);
getContentPane().add(checkBox);

//
setBounds(600, 300, 450, 450);
setVisible(true);

}
public static void main(String[] args){
new TTTTTTT();
}
}

你可能感兴趣的:(java,密码,明文,密码显示)