java密码提示框小例子
2021-02-13 11:16
标签:jpa add else label hoc title date() field main package java1; //使用时替换成读者的包名 import javax.swing.*; class Jf extends JFrame implements ActionListener{ java密码提示框小例子 标签:jpa add else label hoc title date() field main 原文地址:https://www.cnblogs.com/nanfengnan/p/12727214.html
//密码框的示例
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.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();
}
}