Creating the Rink
Like the Aquarium application, where the tank was created in the constructor, the hockey rink is created in Slapshot!'s constructor. Some of this constructor will be familiar from the Aquarium project in the previous chapter, but there's a lot more going on here.
To let the user select options—starting a game, ending one, setting the speed, and so on—this application uses a menu system. After creating a menu bar, the code creates a File menu and stocks it with items such as Start, End, Set Speed…, and Exit. These menu items are connected to the code using an action listener, which means the Slapshot class must implement the ActionListener interface and add an actionPerformed method to handle menu selections. The menu items are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access