![](/img/trans.png)
[英]How do I code a pop up dialog box to appear when the user clicks the X button to exit the program?
[英]How do i make a Dialog box show up when a person has failed to put the correct password?
好的,这是我需要工作的代码,其余的我认为可能无关紧要。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
int failT = 1;
String answer = pass.getText();
if (answer.equals(password)){
System.out.println("CORRECT!!");
pass.setText("");
}
else {
failT =+ 1;
pass.setText("");
if (failT >= 3){
JOptionPane.showMessageDialog(null, "SORRY, you have failed 3 times goodbye");
}
}
}
我认为你应该更换
failT =+ 1;
与
failT += 1;
failT
是actionPerormed
方法的局部变量,每次调用该方法时都会将其初始化为1
,这意味着该值不可能>= 3
等于>= 3
您需要定义主题值作为类/实例字段,所以它的值保持在一流水平,而不是
看看理解类成员的更多细节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.