
import javax.swing.*; import java.util.regex.*; public class joptionpane { public static void main(String[] args){ int category_user = 0; boolean aa = false; do{ String input = JOptionPane.showInputDialog( null,
"Please select the category \n"
+ "1. IT \n"
+ "2. Science \n"
+ "3. Maths",
"Input",
JOptionPane.INFORMATION_MESSAGE
);
Pattern p = Pattern.compile("[A-Z,a-z,&%$#@!()*^]");
Matcher m = p.matcher(input);
if (m.find()) {
JOptionPane.showMessageDialog(null, "Please enter only numbers");
}
else (m.find())
{
category_user = Integer.parseInt(input);
}
}while (!aa || category_user < 1 || category_user>4);
}
\ hello!!please help me!i need to validate the user input on the joptionpane,and if the user enter is a character then it is supposed to return the select category question again.if the user enter correct then the loop will break.however, the following do while will keep looping!how do i modify the codes to make it right?thank for your help.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.