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.

  1. In initGUI(), add an action listener to endButton to call endGame() when the button is clicked using JButton’s addActionListener() method, with a new ActionListener object as the parameter value. In the ActionListener, add a public method called actionPerformed(). actionPerformed() should have one parameter, an ActionEvent, and return nothing. In actionPerformed(), call endGame().

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.