正如标题所述,为什么在此摘要中仅执行最后一个案例声明?
为了清楚起见,我用自己的代码添加了整个开关盒。
提前感谢您的帮助!
int steps = 3;
switch (steps) {
case 1:
int choice1 = JOptionPane.showConfirmDialog(this, "Wilt u suiker bij de koffie?", "Vraag", JOptionPane.YES_NO_OPTION);
if (choice1 == JOptionPane.YES_OPTION) {
b1.setSuiker(true);
} else {
b1.setSuiker(false);
}
break;
case 2:
int choice2 = JOptionPane.showConfirmDialog(this, "Wilt u melk bij de koffie?", "Vraag", JOptionPane.YES_NO_OPTION);
if (choice2 == JOptionPane.YES_OPTION) {
b1.setMelk(true);
} else {
b1.setMelk(false);
}
break;
case 3:
String choice3 = JOptionPane.showInputDialog("Heeft u nog extra wensen?");
b1.setSpecialeWensen(choice3);
System.out.println(b1.toString());
break;
}
}
我认为您必须在default
语句中添加switch
语句。