试图创建一个 joptionpane 来解决为什么这不起作用的任何想法?
public void playerLost() {
if(player.getStaminaLevel() < player.getStaminaNeededToMove(Terrain.SAND)) {
JOptionPane.YES_NO_OPTION(
if (JOptionPane.NO_OPTION) {
dispose();
}
else
{
game = new Game();
createGridSquarePanels();
update();
}
}
我也试过这个,但说 JOptionPane.NO_OPTION 不能从 int 转换为 string
public void playerLost() {
if(player.getStaminaLevel() < player.getStaminaNeededToMove(Terrain.SAND)) {
int choice = JOptionPane.showConfirmDialog(
this,
"sorry you lost\nWould you like to restart?",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if (choice == JOptionPane.NO_OPTION) {
dispose();
}
else
{
game = new Game();
createGridSquarePanels();
update();
}
}
}