JOptionPane取消按钮不会取消窗外?

时间:2015-07-27 06:28:33

标签: java swing joptionpane

所以,我正在制作一个简单的猜谜游戏,当用户按下取消按钮时,程序不会退出循环。这是循环

while(playAgain = true){
        int n = JOptionPane.showConfirmDialog(null, fields, "Number guessing game", JOptionPane.CANCEL_OPTION);

        if(n == JOptionPane.CANCEL_OPTION){
            playAgain = false;
        }

        int randomNumber = randomNumber();

        String guess = input.getText();
        compare(randomNumber, Integer.parseInt(guess));

    }

1 个答案:

答案 0 :(得分:10)

应该是

while(playAgain == true){

while(playAgain){

不要将[=] true分配给playagain使用比较[==]。 你所做的是将true指定给playagain,然后检查是否为true。所以它总是如此