我在测试环境中有以下方法,我正在尝试附加变量count“loginAttempts
”
到JOptionPane
窗口,以便用户知道到目前为止他们有多少次失败的登录尝试。
基本上,如果可能的话,我想将另一个字符串和变量连接到此行。
JOptionPane.showMessageDialog(null, "Enter a valid username and a password. You've had ||loginAttempts|| "failed login attempts", "Error", JOptionPane.ERROR_MESSAGE);
Here's the method out of the application"
private void loginButton(java.awt.event.ActionEvent evt) {
username = userName.getText();
password = userPassword.getText();
if (username.equals(finalusername) && password.equals(finalpassword) && loginAttempts <= 3) {
loginSuccess = true;
} else {
loginSuccess = false;
loginAttempts = loginAttempts + 1;
}
if (loginSuccess) {
JOptionPane.showMessageDialog(null, "You have successfully logged in", "Success", JOptionPane.DEFAULT_OPTION);
} else if (loginAttempts > 3) {
JOptionPane.showMessageDialog(null, "You have had 3 failed login attempt, your account has been locked","Locked", JOptionPane.ERROR_MESSAGE);
} else if (!loginSuccess) {
JOptionPane.showMessageDialog(null, "Enter a valid username and a password", "Error", JOptionPane.ERROR_MESSAGE);
}
}
答案 0 :(得分:0)
你可以用这种方式连接(用其替换最后一个):
} else if (!loginSuccess) {
JOptionPane.showMessageDialog(null, "Enter a valid username and a password, Number of attempts : "+loginAttempts , "Error", JOptionPane.ERROR_MESSAGE);
}