这是我的代码。它从文本文件中读取并将其与用户输入进行比较。我一直在尝试添加一个计数器,一旦count=3做某事,但我就是无法让它工作。我觉得它应该很容易……
boolean login = false;
while (read.nextLine() !=null) {
String user = read.next();
String pass = read.next();
read.next();
if(usernameT.getText().equals(user) && passwordT.getText().equals(pass)) {
login = true;
break;
}
}
if (login) {
new Menu();
} else {
JOptionPane.showMessageDialog(null, "Incorrect username or password");
usernameT.setText("");
passwordT.setText("");
}
我是否在沿着写作线思考?
For(count=0;count<4){
if(login)
new Menu();
else {
JOptionPane.showMessageDialog(null, "Incorrect
username or password");
usernameT.setText("");
passwordT.setText("");
Count++
}
}