在SpaceInvadersApp.gameEnded()(如下所示)中,我如何使用JOptionPane.showInputDialog() 在用户初始Game Over消息对话框后显示一个对话框 谁以大于零的分数赢得比赛(isGameWon方法测试这个)。新对话框应告知用户他们已获得高分,并请求他们的名称为高分表。
public void gameEnded() {
String message;
if (game.isGameWon()) {
message = "You defeated the alien menace! Congratulations!\n\n"
+ "Your score was " + game.getScore();
} else {
message = "Oh no! The aliens have defeated you.";
}
JOptionPane.showMessageDialog(this,
message, "Game Over",
JOptionPane.INFORMATION_MESSAGE);
menuItemGamePause.setEnabled(false);
}
答案 0 :(得分:3)
首先看一下How to Make Dialogs
但基本上,你可以做点像......
if (game.isGameWon()) {
message = "You defeated the alien menace! Congratulations!\n\n"
+ "Your score was " + game.getScore();
String name = JOptionPane.showInputDialog(this, message, "Game Over", JOptionPane.INFORMATION_MESSAGE)
if (name != null) {
// Save name
}
} else {
message = "Oh no! The aliens have defeated you.";
JOptionPane.showMessageDialog(this,
message, "Game Over",
JOptionPane.INFORMATION_MESSAGE);
}