- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个小弹出游戏。我已经添加了故事,一切都运行得很好,直到我添加了这段代码:
Object[] choices = null;
Object[] options = { "Caitlyn", "Warwick", "Teemo", "Olaf", "Ashe" };
int select = JOptionPane.showOptionDialog(null, "Who do you want to fight against?", "Champion selection",
JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, action
);
现在,这些选项出现在出现的每个选项对话框中。我该如何解决这个问题?
这是我的代码
Object[] choices = null;
Object[] options = { "Caitlyn", "Warwick", "Teemo", "Olaf", "Ashe" };
int select = JOptionPane.showOptionDialog(null, "Who do you want to fight against?", "Champion selection",
JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, action
);
switch (select)
{
case 0:
int cait = 0;
cait++;
JOptionPane.showMessageDialog(null, "You will be fighting against the following champion:" + " " + caitlyn.Champion + " " + "\n She is level" + " " + caitlyn.Level + " " + "\n And she is a " + caitlyn.Type + "-Champion");
JOptionPane.showMessageDialog(null, "You have started with 2000HP, Caitlyn has 1700HP.");
// health
newchamp.health = 2000;
caitlyn.enemyhealth = 1700;
//begin
Object[] choices1 = null;
Object[] options1 = { "Criticals", "Pure Damage", "Heal 300 points", "Flee" };
int action = JOptionPane.showOptionDialog(null, "What will you do?", "action",
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
null, options, options[0]);
switch (action)
{
case 0:
int Criticals = (int) (Math.random()*500);
Criticals++;
caitlyn.enemyhealth = (caitlyn.enemyhealth-Criticals);
JOptionPane.showMessageDialog(null, "Caitlyn now has" +" " + caitlyn.enemyhealth + "HP left");
break;
case 1:
int PureDamage = (int) (Math.random()*300);
PureDamage++;
caitlyn.enemyhealth = (caitlyn.enemyhealth-PureDamage);
JOptionPane.showMessageDialog(null, "Caitlyn now has" + " " + caitlyn.enemyhealth + "HP left");
break;
case 2:
int heal = 300;
heal++;
newchamp.health = (newchamp.health+heal);
JOptionPane.showMessageDialog(null, "You now have"+ " " + newchamp.health + "HP points!");
break;
case 3:
String flee;
JOptionPane.showMessageDialog(null, "You failed to flee the battle, better luck next round!");
break;
}
JOptionPane.showMessageDialog(null, "It's Caitlyn's turn now!");
JOptionPane.showMessageDialog(null, "Caitlyn used a damaging attack!");
int enemyDamage = (int) (Math.random()*350);
newchamp.health = (newchamp.health - enemyDamage);
JOptionPane.showMessageDialog(null, "You now have" + " " + newchamp.health +" "+ " HP Left");
JOptionPane.showMessageDialog(null, "It's your turn again!");
Object[] choices2 = null;
Object[] options2 = { "Criticals", "Pure Damage", "Heal 300 points", "Flee" };
int action1 = JOptionPane.showOptionDialog(null, "What will you do?", "action",
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
null, options, options[0]);
switch (action1)
{
case 0:
int Criticals = (int) (Math.random()*700);
Criticals++;
caitlyn.enemyhealth = (caitlyn.enemyhealth-Criticals);
JOptionPane.showMessageDialog(null, "Caitlyn now has" +" " + caitlyn.enemyhealth + "HP left");
break;
case 1:
int PureDamage = (int) (Math.random()*300);
PureDamage++;
caitlyn.enemyhealth = (caitlyn.enemyhealth-PureDamage);
JOptionPane.showMessageDialog(null, "Caitlyn now has" + " " + caitlyn.enemyhealth + "HP left");
break;
case 2:
int heal = 300;
heal++;
newchamp.health = (newchamp.health+heal);
JOptionPane.showMessageDialog(null, "You now have"+ " " + newchamp.health + "HP points!");
break;
case 3:
String flee;
JOptionPane.showMessageDialog(null,"You have failed to flee the battle, better luck next round!");
break;
}
JOptionPane.showMessageDialog(null, "It's Caitlyn's turn again!");
JOptionPane.showMessageDialog(null, "Caitlyn hit a critical!");
int enemyDamage1 = (int) (Math.random()*650);
newchamp.health = (newchamp.health - enemyDamage);
JOptionPane.showMessageDialog(null, "You now have" + " " + newchamp.health +" "+ " HP Left");
if (caitlyn.enemyhealth < newchamp.health){
JOptionPane.showMessageDialog(null, "Caitlyn is too injured by your strength to continue this battle. You are victorious!");
}
else
JOptionPane.showMessageDialog(null, "You are too injured to continue this battle. You are defeated.");
break;
case 1:
int war = 0;
war++;
JOptionPane.showMessageDialog(null, "Warwick is still being made. This window will now exit the program.");
break;
case 2:
int teem = 0;
teem++;
JOptionPane.showMessageDialog(null, "Teemo is still being made. This window will now exit the program.");
break;
case 3:
int ola = 0;
ola++;
JOptionPane.showMessageDialog(null, "Olaf is still being made. This window will now exit the program.");
break;
case 4:
int ash = 0;
ash++;
JOptionPane.showMessageDialog(null, "Ashe is still being made. This window will now exit the program.");
break;
}
}
}
最佳答案
你注意到这部分代码了吗
Object[] choices2 = null;
Object[] options2 = { "Criticals", "Pure Damage", "Heal 300 points", "Flee" };
int action1 = JOptionPane.showOptionDialog(null, "What will you do?", "action",
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
null, **options**, options[0]);
** 表示可能的问题。不应该是 options2
吗? (还有一些其他地方也可能出现同样的错误)
关于java - JOptionPane.showOptionDialog 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15004083/
我在选项 Pane 中创建了自己的按钮,因为我需要为按钮着色并禁用其中一个按钮以实现我的功能。当我单击其他启用的按钮时,选项 Pane 不会关闭,这里我需要单击十字按钮关闭该对话框。 谁能告诉我如何在
我有一台工作笔记本电脑,连接了两台显示器。我通常在监视器二(这是一个外部监视器)上运行我的应用程序。 在我的应用程序中,我正在调用 JOptionPane.showOptionDialog,但问题是该
我正在尝试为我的程序创建一个 GUI。这个特定的 GUI 使用带有 showOptionDialog 的 JOptionsPane。我在 OptionsPane 中添加了一个面板,它有一些 Actio
我想使用 JOptionPane 创建一个 showOptionDialog,它有两个按钮:公制和英制。 如果说,Metric 被点击,Metric GUI 将加载。相反,如果单击 Imperial,
String[] enrollment = {"first Value", "second value"} int enroll = JOptionPane.showOptionDialog(null
所以它工作正常,但有点困惑我想删除 JOptionPane.showOptionDialog 并简单地添加 2 个按钮,这样代码中就不会那么困惑.............. 我尝试过使用 JButto
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我目前在程序中使用带有五个按钮的自定义 showOptionDialog。这些按钮中的每一个都“连接”到“if”语句。通常,我会使用这样的东西: if (a == JOptionPane.YES_O
我在大学里上过几门 Java 编程类(class),但已经有几年了,所以我很生疏。我决定向我的兄弟请教一项编程任务。他让我写一个程序来测试他在口袋妖怪游戏中元素类型的有效性。该代码大部分工作,但由于某
以下代码显示了预期的对话框,但没有按钮: final JPasswordField passwdField = new JPasswordField(); passwdField.setCol
我得到了以下java代码 Icon icoR = new ImageIcon("src/resources/Republica.png"); Icon icoI = new ImageIcon("
我想以垂直方式表示我的按钮,这是我的代码: 这些是我的按钮标签代码: String[] choices = {"31", "63", "127", "255", "511", "1023", "204
是否可以在JOptionPane.showOptionDialog()中启用最小化选项如果可以,我们如何设置它? 最佳答案 JOptionPane 使用 JDialog 来显示。不幸的是,JDialo
在我的应用程序中,当用户提供输入时需要频繁显示 JOptionPane.showOptionDialog。 有时它不会显示,而是等待用户输入并挂起。 这里我附上了示例代码以重现相同的内容。 impor
我使用 JOptionPane.showOptionDialog 方法在 Java swing 中创建了一个选项对话框。该对话框包含不同的按钮,其中有一个“取消”按钮。我想将一个监听器方法附加到此“取
好的,事情就这样了。目前,我正在使用这个: String[] choices = {"Rock", "Paper", "Scissors"}; String input = (String) JO
我是第一次在 JavaFX 项目上工作,这是我的问题: 我有一个 MainApp,从那里我打开主窗口,在那里我有一个菜单栏,从菜单栏我打开一个新窗口,这在主应用程序的 Controller 中调用。
我试图将一个 TextBox 和一个 Button 水平放置在 JOptionPane.showOptionDialog 中。我用过这段代码。 JTextField txt = new JTextFi
如果您使用的数组,比方说长度为 15,并且您想一次显示它们,它会在一个很长的显示框中并排显示它们: String[] options = {"Option 1","Option 2","Option
因此,这是我正在处理的项目中经过编辑的一小段代码,我需要能够从此 showOptionDialog 获取字符串值并将其显示在 showMessageDialog 中,但我一生都无法弄清楚如何实现,不幸
我是一名优秀的程序员,十分优秀!