title: How to make an image replace a JButton when clicked
body: <p>Currently trying to make a TicTacToe game, i have the frame and 9 buttons set up (for each square the players can choose). I'm having a bit of trouble adding functions to each button when clicked.</p>
  
  <pre><code>package OX;
  
  import javax.swing.*;
  import java.awt.*;
  
  public class OX{
  
  public static void main(String[] args){
      JFrame frame = new JFrame("OX");
      frame.setSize(800,800);
      frame.setVisible(true);
      frame.getContentPane().setBackground(Color.BLACK);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JPanel panel = new JPanel(new GridBagLayout());
      frame.add(panel);
      GridBagConstraints c = new GridBagConstraints();
      JButton button1 = new JButton("1");
      button1.setPreferredSize(new Dimension(100,100));
      c.gridx = 1;
      c.gridy = 1;
      c.insets = new Insets(50,50,50,50);     
      panel.add(button1, c);
      JButton button2 = new JButton("2");
      button2.setPreferredSize(new Dimension(100,100));
      c.gridx = 2;
      c.gridy = 1;
      panel.add(button2, c);
      JButton button3 = new JButton("3");
      button3.setPreferredSize(new Dimension(100,100));
      c.gridx = 3;
      c.gridy = 1;
      panel.add(button3, c);
      JButton button4 = new JButton("4");
      button4.setPreferredSize(new Dimension(100,100));
      c.gridx = 1;
      c.gridy = 2;
      panel.add(button4, c);
      JButton button5 = new JButton("5");
      button5.setPreferredSize(new Dimension(100,100));
      c.gridx = 2;
      c.gridy = 2;
      panel.add(button5, c);
      JButton button6 = new JButton("6");
      button6.setPreferredSize(new Dimension(100,100));
      c.gridx = 3;
      c.gridy = 2;
      panel.add(button6, c);
      JButton button7 = new JButton("7");
      button7.setPreferredSize(new Dimension(100,100));
      c.gridx = 1;
      c.gridy = 3;
      panel.add(button7, c);
      JButton button8 = new JButton("8");
      button8.setPreferredSize(new Dimension(100,100));
      c.gridx = 2;
      c.gridy = 3;
      panel.add(button8, c);
      JButton button9 = new JButton("9");
      button9.setPreferredSize(new Dimension(100,100));
      c.gridx = 3;
      c.gridy = 3;
      panel.add(button9, c);      
    }
  }
  </code></pre>
  
  <p>I've tried lots of different ideas but just cant seem to get it right.</p>
  
  <p>thanks!</p>