Hi, I've came across an unusual problem and its related to an application that i'm working on at the moment which uses JOptionPane to prompt for user input. The problem came after JOptionPane was entered into the codes; to prompt for a specific input, and generates the necessary pop-ups.
sample code from my program:
public void addEmployee() { //adds an employee to the array of employees int[] numbers; boolean again=true; Date d=null;
JOptionPane.showInputDialog("Enter name of employee"); String name = MyInput.readString(); do{ JOptionPane.showInputDialog("Enter hire day of employee(YEAR/MM/DD)"); String date = MyInput.readString();
StringTokenizer tokenizer = new StringTokenizer(date, "/"); numbers=new int[3]; String[] tokens = new String[3]; String token="";
//Catch the exceptions that might be thrown if the user enters invalid values for the date //egs, adlj/2/3 or 99/02. In case invalid input is given, prompt for the value again.
try { for (int ii = 0; ii<3; ii++) { tokens[ii] = tokenizer.nextToken(); numbers[ii]=Integer.parseInt(tokens[ii]); again=false; } } catch (NoSuchElementException e) { JOptionPane.showMessageDialog(null, "Error in date format, should enter YEAR/MM/DD"); again=true; } catch (NumberFormatException e) {JOptionPane.showMessageDialog(null, "Error in date format, should enter YEAR/MM/DD"); again=true; } }while (again);
d = new Date(numbers [0],numbers[1],numbers[2]);
Currently, a correct data entered generates the JOptionPane pop-up intended to handle invalid input. so my question is: what can be done so that the program will run through the valid data entered, perform the necessary exception-handling routines for invalid data, and continue on running?