尝试显示错误消息,以便当用户输入错误三次时,将显示错误消息"帐户被阻止".为什么每次输入错误的引脚时pinAttempts ++都不会加1?
try {
int pinAttempts = 0;
int pin = Integer.parseInt(enterPinJTextField.getText());
if (pinAttempts == 3) {
JOptionPane.showMessageDialog(popupFrame, "Account blocked!");
}
if (pin != PIN) {
pinAttempts++;
JOptionPane.showMessageDialog(popupFrame, "Please enter correct pin!");
} else {
BankAccount application = new BankAccount();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} catch (NumberFormatException exception) {
JOptionPane.showMessageDialog(popupFrame, "Please enter a number");
}
Run Code Online (Sandbox Code Playgroud) java ×1