title: Tic Tac Toe with GUI
body: <p>Okay, I want to create a Tic Tac Toe(X-O) game with GUI, I have drawn it but I'm somehow unable to function it. I do know how to use .addActionListener, and I can set a certain button to "X" or "O", but how do I make it so the first button click turns it to X, the second to O and so on. .addActionListener wont work properly because I have to use it on a certain button, but I don't know which button will be pressed.</p>
  
  <p>Here's the code I've written.</p>
  
  <pre><code>public class XO {
  public static void main(String[] args) {
      JFrame myForm=new JFrame("X-O");
      myForm.setSize(255, 300);
      myForm.setLocation(0, 0);
  
      JButton []buttons=new JButton[10];
      int x=40, y=0;
      for(int i=0;i&lt;10;i++)
      {
          if(i%3==0)
          {
              y+=50; x=40;
          }
          buttons[i]=new JButton((i+1)+"");
          buttons[i].setSize(50, 50);
          buttons[i].setLocation(x, y);
          myForm.add(buttons[i]);
          x+=50;
      }
      buttons[9].setText("Start Over");
      buttons[9].setLocation(80, 205);
      buttons[9].setSize(70, 50);
      buttons[9].setMargin(new Insets(0, 0, 0, 0));
  
      buttons[0].addActionListener(new ActionListener() {
  
          @Override
          public void actionPerformed(ActionEvent e) {
  
          buttons[0].setText("X");
          buttons[0].setForeground(Color.BLUE);
          buttons[0].setFont(new Font("Arial", Font.PLAIN, 30));
          buttons[0].setMargin(new Insets(0, 0, 0, 0));
          buttons[0].setEnabled(false);
          }
      });
  
      myForm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      myForm.setLayout(null);
      myForm.setVisible(true);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>As you can see, I will have to use .setActionListener on a specific button, but I dont know which button will be pressed. I hope you get what I mean.
  Thanks in advance.</p>