Step 1


Overview

In this step, you will lay out the major components: The components are added in the TicTacToe class, which is the JApplet subclass for this applet.

The TicTacToe Class

Define the TicTacToe class to extend the JApplet class. You will need four instance variables described in the following table.
Type Name Details
JButton startNewGameButton "Start New Game"
JButton makeComputerPlayButton "Make Computer Play"
JPanel board 3 by 3 grid layout manager
Jlabel message "Push Start New Game button."

In the applet init() method, first disable makeComputerPlayButton. Then create a JPanel with a 1 by 2 grid layout manager for the two buttons. Install the two buttons into this panel. Use a BorderLayout as a layout manager for the applet. Install buttonPanel, board, and message as the north, center, and south components of the applet.

The TicTacToe.html File

The HTML file <applet> tag should specify the TicTacToe class as the code file and should specify the size as 360 by 404. The title should be "Tic Tac Toe Applet".

After you have created the two files, compile your TicTacToe class and run the applet with appletviewer. Your applet should look like the following demonstration applet.

Demonstration Applet