みんな 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;
}
}