伙计们,我正在尝试使用 JOptionPane,但取消按钮正在响应,就好像我输入了错误的输入值并且没有退出程序一样。任何非常有用的想法!
int n = 0, k = 0;
Students stu = new Students();
while (n <= 0) {
try {
n = Integer.parseInt(JOptionPane.showInputDialog(stu, "Enter the number of people","Input", JOptionPane.INFORMATION_MESSAGE));
if (n <= 0) {
OptionPane.showMessageDialog(stu, "You have given a wrong input!",
"Warning", JOptionPane.WARNING_MESSAGE);
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(stu, "You have given a wrong input!",
"Warning", JOptionPane.WARNING_MESSAGE);
n = 0;
}
}