So, I am making a simple guessing game, and the program will not exit the loop when the user presses the cancel button. Here loop
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)); }
source share