Угадайку - JButton doClick не работает? - PullRequest
1 голос
/ 23 марта 2020

Я пытаюсь указать, когда, если игра выиграна или проиграна, она спрашивает пользователя, хотят ли они играть снова. Если да, функция doClick должна нажать кнопку перезагрузки и перезапустить игру, но это не работает?

                if (GuessNumber == theNumber) {
                    statusLabel.setText("Winner! Guess is correct.");
                    statusLabel.setForeground(Color.green);
                    guessTF.setEditable(false);
                    guessTF.setBackground(Color.green);
                    int newGame = JOptionPane.showConfirmDialog(null, "Winner! Congratulations you have won."
                            + "\nYou guessed " +theNumber
                            + "\nWould you like to play again?" , "Guessing Game", JOptionPane.YES_NO_OPTION);
                    if(newGame == JOptionPane.YES_OPTION)
                    {
                        newGameButton.doClick();
                    }
                    else 
                    {
                        int no = JOptionPane.showConfirmDialog(null, "Are you sure you want to quit Guessing Game?", "Guessing Game", JOptionPane.YES_NO_OPTION);
             if(no == JOptionPane.YES_OPTION)
            {
            System.exit(0);
            }
                    }
                }

                if (maxAttempt == 10 && GuessNumber != theNumber) {
                    statusLabel.setText("Game Over. You have exceeded your guessing limit.");
                    statusLabel.setForeground(Color.red);
                    guessTF.setEditable(false);
                    guessTF.setBackground(Color.red);
                    int gameNew = JOptionPane.showConfirmDialog(null, "Game over.\n The guessing limit has been exceeded :("
                            + "\nThe number was: " +theNumber
                            + "\nWould you like to play again?" , "Guessing Game", JOptionPane.YES_NO_OPTION);
                    if(gameNew == JOptionPane.YES_OPTION)
                    {
                        newGameButton.doClick();
                    }
                    else 
                    {
                        int no = JOptionPane.showConfirmDialog(null, "Are you sure you want to quit Guessing Game?", "Guessing Game", JOptionPane.YES_NO_OPTION);
             if(no == JOptionPane.YES_OPTION)
            {
            System.exit(0);
            }
                    }
                }


            }
...