In this exercise you will write a GuiPlayer for use with Graphics Case Study 8. Start with the version available at Y:\zips\
Close all other projects.
Make sure your project is using the project gcs08-gui. If not, you are using the wrong version.

You will be working in groups of two or three. Each member of the group will work independently, following the steps below. When you have finished one of the steps, check with the other members of your group. You may not continue until all members of the group have finished that step. Spend your time helping the other members of your group. Do not write any code for them or show thme your code, but help them by answering questions or making suggestions.

Perform the following to create GuiPlayer from the skeleton code:

  1. Rename GuiPlayerSkeleton to GuiPlayer.
    Modify TicTacToe so that the second player is GuiPlayer.
    The first player should be SmartComputerPlayer at level 3.
    Run the program and make sure it behaves correctly.
    The computer should make the first move and be waiting for the GuiPlayer to move.
    Wait for your other group members to finish this step before continuing.
  2. Write a method:
    private JFrame makeMainFrame(int boardsize);
    that returns a frame that for boardsize=3 looks like:

    The frame title should contain your name.
    Instead of using pack use setSize(400,400);
    Create three atributes:
    generalLabel: for the top label
    informLabel: for the bottom label
    buttons: a two-dimensional array of buttons for the center.
    Call this method for boardsize=3 in the constructor and make the frame visible.
    Run the program and make sure it works.
    It should display the frame. Wait for your other group members to finish this step before continuing.
  3. Take the call to the method out of the constructor.
    Make a JFrame attribute mainFrame initialized to null.
    In boardChanged, if mainFrame is null, set it to the result of makeMainFrame using the boardsize gotten from the board parameter.
    Try this for various values of the board size (change the value in
    Wait for your other group members to finish this step before continuing.
  4. In boardChanged fill each button with the corresponding value from the board array.
    In inform fill the informLabel with the string parameter.
    In setId fill the generalLabel with an appropriate message indicating whether the user is X or O.
    If the two labels do not seem to be set, or if there is some other problem, figure out why and fix this.
    Wait for your other group members to finish this step before continuing.
  5. Add a listener for each button that sends the corresponding move to the game.
    Your program is now compelete.
    You can try to add additional features.
    Here is one possibility: Disable the buttons when it is not your turn.
    You can enable or disable a button using the setEnabled method of JButton which takes one boolean parameter.
  6. Run your program with the your GUI as X and the SmartComputerPlayer as O on level 5.
    That is, start it with:
    new SmartCompuaterPlayer(game,5);
    Figure our how this can be so smart.
    If you and your group have completed this step, you may help other groups.