尝试创建一个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转换为字符串
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();
}
}
}
答案 0 :(得分:1)
第一个代码段无法编译,因为语法对于使用JOptionPane
无效。
在第二段代码中,您缺少标题参数
int choice = JOptionPane.showConfirmDialog(this,
"sorry you lost\nWould you like to restart?",
"Title",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);