-3

I am just not sure exactly what this section of code means.

try {
    startGame(Integer.parseInt(clickedButton.getLabel()));
} catch (Exception ex) {
    Logger.getLogger(JavaGame.class.getName()).log(Level.SEVERE, null, ex);
JJJ
  • 32,902
  • 20
  • 89
  • 102

2 Answers2

1

Integer.parseInt() takes in a String and returns an int. So the label of that button must be String that holds a numeric value. The method startGame must take in an int to know which game to start. If the label is NOT a number, it will go into the catch block by throwing a NumberFormatException.

The catch part is log4j that will output to either a log file and/or console (depends on configuation) with the exception.

Ascalonian
  • 14,409
  • 18
  • 71
  • 103
0

If Integer.parseInt() can not convert what ever string that is in clickedButton's Label then it will throw an error.

The error will then get catched by the try catch and create a log message with a level of severe with the stack trace that had happened.

It threw an exception because the clickedButton's Label is not a number.

Dave P
  • 156
  • 1
  • 8