[英]Trouble with JOptionPane and getting it to work
trying to create a joptionpane to work any ideas why this isnt working? 试图创建一个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();
}
}
i also tried this but says JOptionPane.NO_OPTION cannot be converted from int to string 我也试过了,但是说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();
}
}
}
The first snippet doesn't compile as the syntax is invalid for using a JOptionPane
. 第一个代码段无法编译,因为语法对于使用
JOptionPane
无效。
In the second piece of code, you're missing the title argument 在第二段代码中,您缺少title参数
int choice = JOptionPane.showConfirmDialog(this,
"sorry you lost\nWould you like to restart?",
"Title",
JOptionPane.YES_NO_OPTION,
JOptionPane.INFORMATION_MESSAGE);
Consult the JOptionPane javadoc 查阅JOptionPane javadoc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.