@Override /* * (non-Javadoc) * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) * * arg0: Mouse Event on click * return: void * * List of Local Variables: * newBoard: Board object tocheck if win * X: int variable to hold X co-ordinate of mouse * Y: int variable to hold Y co-ordinate of mouse * * Explanation: procedural method that is called on a mouse click */ public void mouseClicked(MouseEvent arg0) { Board newBoard = new Board(); // get mouse co-ords int X = arg0.getX(); int Y = arg0.getY(); // top left is 225, 125 (subtract from mouse co-ordinates) // bottom right 525, 425 (max valid X/Y co-ordinates) if (X > 225 && X < 525 && Y > 125 && Y < 425 && board[(Y - 125) / 100][(X - 225) / 100] == 0 && newBoard.checkWin(board) < 0) { if (player == 1 && ifAI1 == false || player == 2 && ifAI2 == false) { board[(Y - 125) / 100][(X - 225) / 100] = player; // change board if (player == 1) { // change player turn player++; } else { player--; } repaint(); // repaint } } }