【发布时间】:2017-04-20 20:52:05
【问题描述】:
我有两个下拉列表,我想在选择它们后使用它们我希望根据选择弹出另一个框以显示信息。当我尝试使用 if 语句并按下 OK 按钮时,它只会继续到下一行。我从 showmessagedialog 开始,但我想在某些下拉选项中显示警告。它不工作。我还需要能够循环回到主菜单,以便他们做出不同的选择。
我现在拥有的示例:
int x = JOptionPane.showOptionDialog(null, "Zookeepers would you like to view animal activities or monitor habitats?",
"Welcome to the Brooklyn Zoo!", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon, options, options[0]);
System.out.println(x);
if(x==0){
String[] choices = {"Lions","Tigers","Bears","Giraffes",};
String input = (String) JOptionPane.showInputDialog(null,"Select Animal:","Zoo Animals",
JOptionPane.QUESTION_MESSAGE,null,choices,choices[1]);
if (choices.equals("Lions"));
String [] button = {"OK","Cancel","Warning"};
JOptionPane.showOptionDialog(null, "\"Animal: Lion\\nName: Leo\\nAge: 5 \\nFeeding Schedule: Twice daily\\n\\nALERT: Cut on left front paw",
"Animal",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE, options, options [0]);
【问题讨论】:
-
1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) 使用逻辑一致的缩进代码行和块的形式。缩进是为了让代码的流程更容易理解!
标签: java swing if-statement joptionpane dropdown