我正在开发一个验证 id 和密码的程序,我认为我在验证时遇到了无限循环。当我单击登录按钮时,没有任何反应。我是 Java 新手,还不知道要寻找什么来解决这个问题。
代码如下:
public void actionPerformed(ActionEvent e) {
success = false;
// Sequential search
int i = 0;
while (i < validID.length) {
;
}
{
if (idField.getText().compareTo(validID[i]) == 0) {
if (passwordField.getText().compareTo(validPassword[i]) == 0) {
success = true;
}
}
i = i + 1;
}
if (success == true) {
headerLabel.setText("Login successful");
idField.setText("");
passwordField.setText("");
idField.requestFocus();
} else {
headerLabel.setText("Unsuccessful. Try Again");
idField.setText("");
passwordField.setText("");
idField.requestFocus();
}
repaint();
}