在do while
循环中,它检查用户是否输入了任何字母或0
,但是当我点击其cancel
中的JOptionPane
按钮时循环再次而不是退出JOptionPane
do {
try {
op = JOptionPane.showInputDialog(null, "How Many Elements do you want in the universe?");
opi = Integer.parseInt(op);
if (op.equals("0")) {
JOptionPane.showMessageDialog(null, "The Universe cannot be empty");
try_Error = false;
} else {
try_Error = true;
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Enter Numbers Only");
try_Error = false;
}
} while (!try_Error);