JOptionPane输入对话框取消按钮正在进入Do While循环

时间:2017-04-15 20:43:11

标签: java do-while joptionpane

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); 

0 个答案:

没有答案