CIS 260 - Graphical TicTacToe (GUI)

The objectives of this assignment are:

  1. create a GUI to play TicTacToe
  2. use your previously implemented TitTacToe class

Assignment

This assignment is all about creating and using a Java GUI and reusing a class you have previously designed. You should already have a TicTacToe class which represents a TicTacToe board. You now have to create a GUI interface to replace the text interface you previously used.

Requirements for your Java class

  1. Make sure your old TicTacToe.java code is in the same directory.
  2. It should extend a JFrame and implement the MouseListener interface.
  3. It should contain a private class named TTTLabel. TTTLabel should extend JLabel and add a public instance integer field named tag. The field should be initialized to -1.
  4. It should contain the following two fields:
    1. an array of nine TTTLabel objects
    2. a reference to a TicTacToe object
  5. It should contain eight methods
    1. main(String[]): create a new object of itself
    2. a constructor which will call createAndShowGUI when the event dispatch thread is ready to run it; it should send a title string ("Tic-Tac-Toe") to createAndShowGUI
    3. createAndShowGUI(String): see notes below for detailed requirements
    4. mouseClicked(MouseEvent): see notes below for detailed requirements
    5. mouseEntered(MouseEvent): do nothing
    6. mouseExited(MouseEvent): do nothing
    7. mousePressed(MouseEvent): do nothing
    8. mouseReleased(MouseEvent): do nothing
  6. createAndShowGUI(String) should do the following:
    1. create a new TicTacToe object
    2. set the layout of the content pane of the object we are in to be a GridLayout
    3. create nine TTTLabel objects to populate the array of TTTLabels, set the tags for those labels to the numbers 1 through 9, set the text to a blank, add the current object as a mouse listener to each label, set the borders and styling on each cell to make it look like the example, and add each cell to the content pane of the object we are in
    4. set the default close operation
    5. make the object we are in 300 pixels wide and 300 pixels tall, and make it visible
  7. mouseClicked(MouseEvent) should do the following:
    1. get the tag value from the label that was clicked
    2. find out from the TicTacToe object what player's move it is
    3. use the tag value and the TicTacToe object to try to make the move that was requested by the mouse click
    4. if the move was valid/accepted, then set the text in the label that was clicked to the correct player character, check the status of the TicTacToe object, and display an appropriate message if the game is no longer TicTacToe.Status.ONGOING
    5. if the game is no longer ongoing, then exit

Sample

TicTacToe game sample image

Grading rubric

Note: Program must compile without errors.

  1. 5 points for following style conventions (no tabs, proper indentation, documentation comments)
  2. 35 points for the GUI working properly
  3. 10 points for the game working properly