title: How do I implement a reset button for my GUI?
body: <p>I am an AP Computer Science student and I need help with my assignment for the class. My assignment is to create a simple GUI or game using Eclipse. I made a simple player vs. player tic-tac-toe game, but I do not know how to create a "reset" button for my GUI. I tried multiple times, but I can't get it to work or show up in my GUI. I would appreciate some pointers on how to implement a functional reset button, so I would not have exit out of my GUI multiple times to start playing again. Here is the code I have written so far. </p>
  
  <pre><code>package gui;
  
  import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class TicTacToeGUI implements ActionListener 
  {
      JFrame window = new JFrame("Tic-Tac-Toe");
      JButton[] button;
      JButton reset = new JButton("Reset"); 
      String letter = "";
      public int count = 0;
      public boolean win = false;
  
      public TicTacToeGUI()
      {
          button = new JButton[9];
          window.setSize(300,300);
          window.setLayout(new GridLayout(3,3));
          JButton dummy = new JButton("");
          Font font = dummy.getFont();
          Font bigFont = font.deriveFont(font.getSize2D() * 5.0f);
          JButton reset = new JButton("Reset");
          for(int i = 0; i &lt; 9; i++) 
          {
              button[i] = new JButton("");
              button[i].setFont(bigFont);
              button[i].addActionListener(this);
              window.add(button[i]);
          }
          window.setVisible(true);
      }
  
      public void actionPerformed(ActionEvent a) 
      {
          count++;
  
          if(count % 2 == 1)
          {
              letter = "X";
          }
          else
          {
              letter = "O";
          }
  
          Object but = a.getSource();
  
          for(int i = 0; i &lt; 9; i++) 
          {
              if(but == button[i]) 
              {
                  button[i].setText(letter);
                  button[i].setEnabled(false);
                  break;
              }
          }
  
          if( button[0].getText() == button[1].getText() &amp;&amp; button[1].getText() == button[2].getText() &amp;&amp; button[0].getText() != "")
          {
              win = true;
          }
          else if(button[3].getText() == button[4].getText() &amp;&amp; button[4].getText() == button[5].getText() &amp;&amp; button[3].getText() != "")
          {
              win = true;
          }
          else if(button[6].getText() == button[7].getText() &amp;&amp; button[7].getText() == button[8].getText() &amp;&amp; button[6].getText() != "")
          {
              win = true;
          }
          else if(button[0].getText() == button[3].getText() &amp;&amp; button[3].getText() == button[6].getText() &amp;&amp; button[0].getText() != "")
          {
              win = true;
          }
          else if(button[1].getText() == button[4].getText() &amp;&amp; button[4].getText() == button[7].getText() &amp;&amp; button[1].getText() != "")
          {
              win = true;
          }
          else if(button[2].getText() == button[5].getText() &amp;&amp; button[5].getText() == button[8].getText() &amp;&amp; button[2].getText() != "")
          {
              win = true;
          }
          else if(button[0].getText() == button[4].getText() &amp;&amp; button[4].getText() == button[8].getText() &amp;&amp; button[0].getText() != "")
          {
              win = true;
          }
          else if(button[2].getText() == button[4].getText() &amp;&amp; button[4].getText() == button[6].getText() &amp;&amp; button[2].getText() != "")
          {
              win = true;
          }
          else 
          {
              win = false;
          }
  
          if(win == true)
          {
              JOptionPane.showMessageDialog(null, letter + " WINS!");
          } 
          else if(count == 9 &amp;&amp; win == false)
          {
              JOptionPane.showMessageDialog(null, "Tie Game!");
          }
      }
  
      public static void main(String[] args)
      {
          new TicTacToeGUI();
      }
  }
  </code></pre>