Save High Scores
Learn to save the ten top high scores along with the dates they were recorded.
Use formatted current date
In this lesson, we will learn to get the current date, format it, and save it to a file.
Reading the previous high scores
When the game ends, WordBuilder will need to save the score if the score is in the top ten high scores, then ask the user if he wants to play again.
Use the End Game button to end the game.
- In
initGUI()
, add an action listener toendButton
to callendGame()
when the button is clicked using JButton’saddActionListener()
method, with a newActionListener
object as the parameter value. In theActionListener
, add a public method calledactionPerformed()
.actionPerformed()
should have one parameter, anActionEvent
, and return nothing. InactionPerformed()
, callendGame()
.
Note: After adding the above code, do not execute the program right away. The code will have a syntax error because endGame()
does not exist yet.
...
private void initGUI() {
...
JButton endButton = new JButton("End Game");
endButton.addActionListener(__________________ {
_____________ actionPerformed(_____________) {
__________();
}
});
buttonPanel.add(endButton);
...
Get hands-on with 1200+ tech skills courses.