【发布时间】:2022-01-26 01:10:35
【问题描述】:
点击取消或退出按钮后如何添加功能?我试过这样,但它对我不起作用。
它向我显示了一个错误,即选择为空,但它不可能是因为它是 int?有没有其他办法解决?
public void start() {
int choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Choice: \n 1 - Play a game \n 2 - show all games \n 3 - Find the best score \n 4 - Find a player \n 5 - End"));
//if (choice == JOptionPane.OK_OPTION) {
switch (choice) {
case 1:
this.play();
break;
case 2:
this.allGames();
break;
case 3:
this.getBestScore();
break;
case 4:
this.getPlayer();
break;
case 5:
System.exit(0);
break;
default:
JOptionPane.showMessageDialog(null, "Wrong input.");
break;
}
// } else if (choice == JOptionPane.CANCEL_OPTION) {
// System.exit(0);
// } else if (choice == JOptionPane.CLOSED_OPTION) {
// System.exit(0);
// }
}
【问题讨论】: