CJCoding With Joseph
15free / daySign inCreate account

Mastering Java Swing

Reset The Game - STEP 8

Tic Tac Toe Game

We’ll create a method called resetBoard that clears the board and prepares it for the next game:

private void resetBoard() {
    for (JButton button : buttons) {
        button.setText(""); // Clear the text on each button
        button.setBackground(null); // Reset the background color
    }
    isXTurn = true; // Start with X's turn
}
Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 27 more lessons in Mastering Java Swing.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.