Alright, so I have run into a bit of an error and I am not sure where I have gone wrong. I have two sets of code that should work together. The problem seems to be in the second file TicTacEvent on line 5. I read something about associating the file, but I do not fully understand what the means or how I am supposed to go about doing that.
void b2() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[0][1].setIcon(a); check[0][1] = 1; } else { gui.boxes[0][1].setIcon(b); check[0][1] = 2; } }
import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TicTacEvent implements ItemListener, ActionListener, Runnable { TicTac gui; Thread playing; ImageIcon a = new ImageIcon("x.jpg"); ImageIcon b = new ImageIcon("o.jpg"); int clicks = 0; int win = 0; int[][] check = new int[3][3]; public TicTacEvent (TicTac in) { gui = in; for (int row=0; row<=2; row++) { for (int col=0; col<=2; col++) { check[row][col]=0; } } } public void actionPerformed (ActionEvent event) { String command = event.getActionCommand(); if (command.equals("Play")) { startPlaying(); } if (command.equals("1")) { b1(); } if (command.equals("2")) { b2(); } if (command.equals("3")) { b3(); } if (command.equals("4")) { b4(); } if (command.equals("5")) { b5(); } if (command.equals("6")) { b6(); } if (command.equals("7")) { b7(); } if (command.equals("8")) { b8(); } if (command.equals("9")) { b9(); } } void b1() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[0][0].setIcon(a); check[0][0] = 1; } else { gui.boxes[0][0].setIcon(b); check[0][0] = 2; } } void b2() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[0][1].setIcon(a); check[0][1] = 1; } else { gui.boxes[0][1].setIcon(b); check[0][1] = 2; } } void b3() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[0][2].setIcon(a); check[0][2] = 1; } else { gui.boxes[0][2].setIcon(b); check[0][2] = 2; } } void b4() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[1][0].setIcon(a); check[1][0] = 1; } else { gui.boxes[1][0].setIcon(b); check[1][0] = 2; } } void b5() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[1][1].setIcon(a); check[1][1] = 1; } else { gui.boxes[1][1].setIcon(b); check[1][1] = 2; } } void b6() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[1][2].setIcon(a); check[1][2] = 1; } else { gui.boxes[1][2].setIcon(b); check[1][2] = 2; } } void b7() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[2][0].setIcon(a); check[2][0] = 1; } else { gui.boxes[2][0].setIcon(b); check[2][0] = 2; } } void b8() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[2][1].setIcon(a); check[2][1] = 1; } else { gui.boxes[2][1].setIcon(b); check[2][1] = 2; } } void b9() { clicks = clicks + 1; if ((clicks%2)==1) { gui.boxes[2][2].setIcon(a); check[2][2] = 1; } else { gui.boxes[2][2].setIcon(b); check[2][2] = 2; } } void startPlaying() { playing = new Thread(this); playing.start(); gui.play.setEnabled(false); } }