身份验证我如何创建一个登录屏幕,允许输入一个通用密码,但在三个三之后程序必须关闭(Java)
信息需要3次尝试,然后程序关闭。
每个用户使用相同的密码
密码设置得太高,密码=12345678。
用户数据是从GUI组件中提取的
我试过的代码:
String password = "12345678";
String userInput = String.valueOf(jPasswordField1.getPassword());
int length = userInput.length();
if (userInput.equals(password)) {
this.dispose();
new INPUT().setVisible(true);
}
else if (!userInput.equals(password)) {
if (length > 9) {
lblValid.setText("To many characters");
tries++;
}
else if (length < 8) {
lblValid.setText("To little characters");
tries++;
}
}
if (tries == 3) {
System.exit(0);
}
# 1 楼答案
您可以使用扫描仪和while循环来实现: