Starting a Game
Because the code has connected the menu items to an action listener, the application will use a method named actionPerformed that's called when the user makes a menu selection. This method is passed an ActionEvent object, whose getSource method returns the menu item the user selected. When the user selects the Start item, menuitem0, the application should begin a new game by telling the new thread to get things started.
The standard technique for communicating with threads is with Boolean flags, and that's how you start a new game. In this case, the worker thread waits until a flag named stop is set to true before running the game. The user may have decided to start a new game in the middle of a current game, so the first order ...
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