
12.13 Layout Managers: GridLayout 897
Example 12.18 shows the GUI client class that enables a user to play the tile
puzzle game.
Each cell of the grid is a button. At line 14, we declare a two-dimensional
array of JButtons named squares. Each element of squares will be a cell in
the game grid. The TilePuzzle instance variable game, declared at line 15,
represents the tile puzzle game that we will display inside the window.
When the user plays, we will call the various methods of the TilePuzzle class
to enforce the rules of the game.
The constructor (lines 17–22) instantiates game and calls the
setUpGameGUI method. We also call the setUpGameGUI method ...