[英]JOptionPane.showMessageDialog having to quit twice
So I have a JOptionPane that appears when a certain condition isn't met and for some reason when I press "Ok" it appears again, but then when pressing "Ok" on the second dialog it goes way. 因此,我有一个JOptionPane,当不满足特定条件时会出现,并且由于某种原因,当我按“ Ok”时,它会再次出现,但是随后在第二个对话框中按“ Ok”时,它就会消失。
Below is the method where the dialog gets made: 下面是制作对话框的方法:
public boolean checkBet()
{
if(currentPlayer.getBet() <= 0)
{
JOptionPane.showMessageDialog(null, "You must place a bet before you can roll your dice!.",
"Bet Required!",
JOptionPane.ERROR_MESSAGE);
return false;
}
else
return true;
}
and this is where the above method gets called: 这就是上面的方法被调用的地方:
@Override
public void actionPerformed(ActionEvent e) {
checkBet();
if(checkBet())
{
setRollingPlayer(currentPlayer);
new Thread() {
@Override
public void run() {
gameEngine.rollPlayer(rollingPlayer, 500, 2000, 500);
}
}.start();
}
}
You're call checkBet
twice in the actionPerformed
method 您在actionPerformed
方法中两次调用checkBet
@Override
public void actionPerformed(ActionEvent e) {
checkBet(); // Here
if(checkBet()) // And here
{
When you are calling function checkBet()
in actionPerformed()
, it has been mentioned two times. 在actionPerformed()
中调用函数checkBet()
时,已被提及两次。 Function checkBet()
will also execute inside if()
. 函数checkBet()
也将在if()
内部执行。
Remove calling once and it will execute once. 删除一次调用,它将执行一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.