End Game After Last Round
Learn to show, update the highest score, and end the game after the last round.
Ending the round
The next step needed for the game is to be able to end a round and add the new points to the score.
- In
initGUI()
, add an action listener toendRoundButton
to callendRound()
when the button is clicked. Use JButton’saddActionListener()
method, with a newActionListener
object as the parameter value. In theActionListener
, add a public method calledactionPerformed()
. TheactionPerformed()
method should takeActionEvent
as a parameter and return nothing. InactionPerformed()
, callendRound()
.
Note: Do not try to execute the code yet. It will have a syntax error because endRound()
does not exist yet.
...
private void initGUI() {
...
JButton endRoundButton = new JButton("End Round");
endRoundButton.addActionListener(__________________ {
_____________ actionPerformed(_____________) {
__________();
}
});
buttonPanel.add(endRoundButton);
...
Get hands-on with 1200+ tech skills courses.