CS 1713 Introduction to Computer Science:
Tic Tac Toe Application
In this activity you will write a Tic Tac Toe Application that is similar
to the TelephoneKaypadApplication from Case Study 17.
This will be a pair programming exercise.
Two students will work together, with one doing the typing and the other helping.
Stop work when there are five minutes left and do the last step.
- Create a new Java project called ttt1.
Create a main program called
TTTPanelTest in the package tictactoe.
- TTTPanelTest will look like TelephoneKeypadApplication
but will add a new TicTacToePanel.
- Create an inner class called TicTacToePanel that extends
JPanel.
The constructor has an integer parameter called
boardSize.
This class will use a BorderLayout which
has a boardSize*boardSize buttons in a square
in the center, and labels in the north and south.
The buttons will
be initialized to contain 3 dollar signs (for testing).
- Test your program.
- Write a public method in TTTPanelTest called inform that has
a String parameter and displays the parameter using the south label.
- Write a public method in TTTPanelTest called setId that
takes a char as a parameter.
It puts the message "You are player x"
in the north label, where x is replaced by the parameter.
- Test your program.
- Write a method called move in TTTPanelTest that takes
two integer parameters.
It outputs a line using System.out.println
describing the two parameters.
- Modify TicTacToePanel so that when one of the buttons is pushed
it calls move with the parameters giving the row and column of the
button.
Hint: look at TelephoneButtonListener and use it as a model to make
a listener for each button.
The constructor of the listener will have
two parameters, the row and column of the button.
- Test your program.
- Write a method in TicTacToePanel called boardChanged
that has a square 2-dimensional array of char as a parameter.
Assume that this is a square array with boardSize rows and columns.
Use this to set the button labels.
- Test your program.
- Modify TTTPanelTest so that it keeps track of a two-dimensional
array of char with boardSize rows and boardSize columns.
Initialize the array to blanks.
Have move set the
corresponding entry to 'X' if the parameters are in range.
It will then
call boardChanged with this two-dimensional array as a parameter.
- Test your program.
- Modify move so that it alternately puts in X's and O's.
- Test your program.
- Last Step: Be sure to start this when there are at least 5 minutes left.
Log into your UTSA email and send a copy of your source file as an attachment
to srobbins@cs.utsa.edu.
Send a copy to yourself and your partner.
In the body of your email, include your name and your partner's name.
Also include the number of the last step you got working.