我想用键 Listener 更改我的 JPasswordField 的颜色。我正在制作注册表单,用户应在密码字段中至少填写 8 个字符,包括数字和字母。有谁能够帮我?
我的代码:
enter code here
public void keyPressed(KeyEvent e) {
if(e.getSource()==passwordField){
if(passwordField.toString().length()>=8)
passwordField.setBackground(Color.GREEN);
else
passwordField.setBackground(Color.RED);
}
}