Error handling java GUI  
Author Message
lamthierry





PostPosted: 2005-6-6 11:17:00 Top

java-programmer, Error handling java GUI Let's say that I'm reading the inputs from a TextField widget:

JTextField jt = new JTextField(20);
String text = jt.getText();

if ( !text.equals("OK") )
{
// print some error message to the user
}

If the input is bad, I want to print some error message to the user but
at the same time I don't want to exit my GUI. How do I do that? Should
I be using exceptions? Can someone point me to some sample codes
somewhere on how error handling is performed in JAVA?

Thanks
Thierry

 
IchBin





PostPosted: 2005-6-6 11:39:00 Top

java-programmer >> Error handling java GUI email***@***.com wrote:
> Let's say that I'm reading the inputs from a TextField widget:
>
> JTextField jt = new JTextField(20);
> String text = jt.getText();
>
> if ( !text.equals("OK") )
> {
> // print some error message to the user
> }
>
> If the input is bad, I want to print some error message to the user but
> at the same time I don't want to exit my GUI. How do I do that? Should
> I be using exceptions? Can someone point me to some sample codes
> somewhere on how error handling is performed in JAVA?
>
> Thanks
> Thierry
>
I usually have an application error class that handles all of my error
stuff. Here are three methods you maybe able to use...


protected static void errorMessage(String errorMessage) {
/**
* Display JPanel Error messages any text Errors. Overloads
* errorMessage(String e)
*/
String method = new
Throwable().getStackTrace()[0].getMethodName()+": +";

Object[] options = { "OK" };
JOptionPane.showOptionDialog(null, errorMessage, "General Message",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE, null,
options, options[0]);

AppLog.setLogToConsole(PROGRAM + method + " ***");
AppLog.setLogToConsole(PROGRAM + method + " *** " +
errorMessage);
AppLog.setLogToConsole(PROGRAM + method + " ***");
}


protected static void errorMessage(String errorHeader,String
errorMessage) {
/**
* Display JPanel Error messages any text Errors. Overloads
* errorMessage(String errorMessage)
*/
String method = new
Throwable().getStackTrace()[0].getMethodName()+": +";

Object[] options = { "OK" };
JOptionPane.showOptionDialog(null, errorMessage, errorHeader,
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE, null,
options, options[0]);

AppLog.setLogToConsole(PROGRAM + method + " ***");
AppLog.setLogToConsole(PROGRAM + method + " *** " +
errorMessage);
AppLog.setLogToConsole(PROGRAM + method + " ***");
}


public static void errorMessage(Exception exceptionMsg) {
/**
* Display JPanel Error messages any SQL Errors. Overloads
* errorMessage(String e)
*/
String method = new
Throwable().getStackTrace()[0].getMethodName()+": +";

Object[] options = { "OK" };
JOptionPane.showOptionDialog(null, exceptionMsg, " ",
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE, null, options, options[0]);

AppLog.setLogToConsole(PROGRAM + method + " ***");
AppLog.setLogToConsole(PROGRAM + method + " *** " +
exceptionMsg);
AppLog.setLogToConsole(PROGRAM + method + " ***");

AppData.ApplicationError = true;

}

--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
__________________________________________________________________________

' If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)