
878 CHAPTER 12 Graphical User Interfaces
108 }
109 // else Close ... , do not draw
110 }
111 }
EXAMPLE 12.12 The SubHunt Class
Example 12.13 shows the GUI client class that enables a user to play the
submarine hunting game.
In this game, the only mouse action we care about is a click; therefore, we
are interested in only one method of the MouseListener interface:
mouseClicked. To simplify our code, we can extend the MouseAdapter class,
which provides implementations for the five MouseListener methods, so
our event handler needs to override only the mouseClicked method.
At lines 11–16, we declare our instance variables. The ints x and y represent
the x