finalized joptionpane fixed
This commit is contained in:
@@ -161,8 +161,18 @@ public class HockeyStats {
|
||||
boolean dataExit = false;
|
||||
int k;
|
||||
try {
|
||||
k = Integer.parseInt(JOptionPane.showInputDialog(menu));
|
||||
String input = JOptionPane.showInputDialog(menu);
|
||||
if (input == null) {
|
||||
throw new NumberFormatException("Cancel or Exit clicked");
|
||||
}
|
||||
if (input == "") {
|
||||
throw new IllegalArgumentException("No input");
|
||||
}
|
||||
k = Integer.parseInt(input);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof NumberFormatException) {
|
||||
return true;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Please choose one of the available menu options!");
|
||||
return false;
|
||||
}
|
||||
@@ -202,6 +212,7 @@ public class HockeyStats {
|
||||
case 2:
|
||||
String rmName =
|
||||
JOptionPane.showInputDialog(null, "Enter the name of the player you want to remove:");
|
||||
if (rmName == null) break;
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
players.removePlayer(rmName)
|
||||
@@ -277,8 +288,18 @@ public class HockeyStats {
|
||||
boolean statsExit = false;
|
||||
int k;
|
||||
try {
|
||||
k = Integer.parseInt(JOptionPane.showInputDialog(menu));
|
||||
String input = JOptionPane.showInputDialog(menu);
|
||||
if (input == null) {
|
||||
throw new NumberFormatException("Cancel or Exit clicked");
|
||||
}
|
||||
if (input == "") {
|
||||
throw new IllegalArgumentException("No input");
|
||||
}
|
||||
k = Integer.parseInt(input);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof NumberFormatException) {
|
||||
return true;
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "Please choose one of the available menu options!");
|
||||
return false;
|
||||
}
|
||||
@@ -302,8 +323,15 @@ public class HockeyStats {
|
||||
JOptionPane.showMessageDialog(null, "Sorted by points");
|
||||
break;
|
||||
case 5:
|
||||
int minGoals =
|
||||
Integer.parseInt(JOptionPane.showInputDialog(null, "Enter the min goals to show:"));
|
||||
String minInput = JOptionPane.showInputDialog(null, "Enter the min goals to show:");
|
||||
if (minInput == null) {
|
||||
break;
|
||||
}
|
||||
if (minInput.equals("")) {
|
||||
JOptionPane.showMessageDialog(null, "Enter a value");
|
||||
break;
|
||||
}
|
||||
int minGoals = Integer.parseInt(minInput);
|
||||
PlayerList pl = players.getPlayersGoalsAbove(minGoals);
|
||||
JOptionPane.showMessageDialog(null, pl.toString());
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user