FaultInOurPong  1
view.HighScore Class Reference

Public Member Functions

 HighScore () throws IOException
 Constructor for the HighScore. More...
 
void checkHighScore (double nameScore, JFrame main) throws IOException
 checks the high score and update the score file More...
 

Static Public Member Functions

static void readFrom () throws IOException
 reads score data. More...
 
static void writeTo ()
 writes the score onto the file More...
 
static boolean isHigh (double nameScored)
 checks whether the score can be in top 20 list More...
 
static int findRank () throws IOException
 determines the rank of a score More...
 
static void highScorePage (JFrame main) throws IOException
 displays the high score More...
 

Constructor & Destructor Documentation

§ HighScore()

view.HighScore.HighScore ( ) throws IOException

Constructor for the HighScore.

calls the read method to read data

Exceptions
IOException

Member Function Documentation

§ checkHighScore()

void view.HighScore.checkHighScore ( double  nameScore,
JFrame  main 
) throws IOException

checks the high score and update the score file

finds the rank for each score and lists them for display

Exceptions
IOExceptioncannot find and read the highScore.txt

Variable declaration

  • the score for each user
  • variables for the JPanel

Define ranks for each score/user

  • Prompt for the user to enter his/her username
  • Pop up a confirmation message after saving

Display the score list

§ findRank()

static int view.HighScore.findRank ( ) throws IOException
static

determines the rank of a score

Returns
a rank of the score
Exceptions
IOExceptioncannot find and read the highScore.txt

Variable declaration

  • the current score list
  • an indicator for the check action
  • a counter for looping through the list

For each score/record, if the current score is greater than the previous one, set this score to have a higher rank and return the rank.

§ highScorePage()

static void view.HighScore.highScorePage ( JFrame  main) throws IOException
static

displays the high score

creates a frame for the display after reading the score file

Exceptions
IOExceptioncannot find and read the highScore.txt

Create a JFrame for the display

Read all the score data and put them into an array

Put all the score data into a JTable for display

§ isHigh()

static boolean view.HighScore.isHigh ( double  nameScored)
static

checks whether the score can be in top 20 list

Returns
a boolean that indicate the score can go into the score list

§ readFrom()

static void view.HighScore.readFrom ( ) throws IOException
static

reads score data.

reads from file "highScore.txt" and store them into an array.

Exceptions
IOExceptioncannot find and read the highScore.txt

Declare a variable to store the file.

  • Read the file using BufferedReader
  • Organize and put user data into the array

§ writeTo()

static void view.HighScore.writeTo ( )
static

writes the score onto the file

opens the file "highScore.txt" and updates scores

Exceptions
IOExceptioncannot find and write the highScore.txt

Declare a variable to store the file name

Use FileWriter to write scores


The documentation for this class was generated from the following file: