The Artima Developer Community
Sponsored Link

Java Answers Forum
JOptionPane - conflict with exception handling?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Tan

Posts: 1
Nickname: cmdrtaco
Registered: Jul, 2002

JOptionPane - conflict with exception handling? Posted: Jul 31, 2002 1:58 AM
Reply to this message Reply
Advertisement
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?

Topic: sorting Previous Topic   Next Topic Topic: USING AN EXISTING C++ DLL WITH JNI

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use