package java1; //使用时替换成读者的包名
//密码框的示例
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class Jf extends JFrame implements ActionListener{
JLabel label = new JLabel("请输入密码:");
JPasswordField txt1Field = new JPasswordField(25);
JButton jButton = new JButton("确定");
JTextField txt2Field = new JTextField(25);
Jf(){
setSize(300,200);
setVisible(true);
setTitle("密码验证");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new FlowLayout());
add(label);
add(txt1Field);
txt1Field.setEchoChar('*');
add(jButton);
add(txt2Field);
validate();
jButton.addActionListener(this);
}
public void actionPerformed(ActionEvent event)
{
if(txt1Field.getText().equals("abc"))
txt2Field.setText("密码正确!!");
else {
txt2Field.setText("密码错误!!");
}
}
}
public class Jpassword {
public static void main(String[] args) {
new Jf();
}
}