Dialog Boxes

K

Ken Kast

I have a non-GUI Java app. Even tho it runs without a UI I want to
have it display error messages as necessary. I've got the following
line of code to do that
JOptionPane.showMessageDialog(null, Msg, Title, Severity);

The app seems to hang up at this point. The debugger shows 4 threads
(besides Main) running: AWT-Shutdown; AWT-Windows; Java2D Disposer;
and AWT-EventQueue-0. Can someone tell me what's going on, and more
importantly, what I need to do different or in addition to get the
dialogs to work.

Thanks.

Ken
 
J

Jim Cobban

Ken Kast said:
I have a non-GUI Java app. Even tho it runs without a UI I want to
have it display error messages as necessary. I've got the following
line of code to do that
JOptionPane.showMessageDialog(null, Msg, Title, Severity);

The app seems to hang up at this point. The debugger shows 4 threads
(besides Main) running: AWT-Shutdown; AWT-Windows; Java2D Disposer;
and AWT-EventQueue-0. Can someone tell me what's going on, and more
importantly, what I need to do different or in addition to get the
dialogs to work.

I haven't tried this and I am not surprised it didn't work. I think you
have to create a main window even if all you are doing is displaying
messages in top level windows.

Even if you wish to leave your code just doing printlns to System.out I
would still advise you to wrap the program in a GUI if you wish to take any
advantage of Swing. It only takes a few lines of code to create a
JTextArea, put it in a JScrollPane, and make that the content pane of a
JWindow. Create a class that extends OutputStream and sends its output to
the JTextArea. That is about 50 lines of code mostly because of the number
of methods you have to overload. Now you can make an instance of that
output stream replace System.out and all of the printlns in your non-GUI
code will appear in the window. This is particularly nice on Windows as it
eliminates losing messages that scroll off the DOS window. Admittedly
attempts to read from System.in need to be replaced by input dialogs.
 
P

Paul Bilnoski

I have a non-GUI Java app. Even tho it runs without a UI I want to
have it display error messages as necessary. I've got the following
line of code to do that
JOptionPane.showMessageDialog(null, Msg, Title, Severity);

The app seems to hang up at this point. The debugger shows 4 threads
(besides Main) running: AWT-Shutdown; AWT-Windows; Java2D Disposer;
and AWT-EventQueue-0. Can someone tell me what's going on, and more
importantly, what I need to do different or in addition to get the
dialogs to work.

To get the threads to shut down, put a 'System.exit(0);' call at the end of
execution. This will stop all the associated AWT listening threads, and not
just the one in which your 'main' is running.
Thanks.

Ken

--Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top