Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Event Queue kills GUI

Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

{Already tried this on java.sun forum - got no response. Hopefully you guys can help}
I have an application which was working fine. Basically a controller class loaded a Monitor class and a Screen class - both which extend JFrame. The class performed some background tasks and sent messages to the Monitor class and Screen class which updated their display to show the progress of the application. This was working fine BUT now I need to put a screen up which allows the users to change the parameters used by the program and kick off the process.

No problem I hear you say : Just add a JFrame with a main method that is called to initiate the application, call the Controller's constructor and call the method to run the process. This will show the screens and run the process as before.

Well NO. The process runs as before but the GUI does not invoke the Monitor class.

The following code shows the working application (without the Parameter view) :

Controller class pseudo code -

Monitor class

This works grand when the program is run by calling the main method of Controller. By stepping through the code I see that the code in the Main thread runs. Less than a second after the last line in the code labelled "// Thread = Main" is reached, the constructor for Monitor is activated in Thread = AWT-EventQueue-0, then the mon.showProgress() method is called, and when the run() method enclosed in the invokeLater() method completes the Monitor JFrame is displayed.
YIPEE works as planned.

However when I add the following class and run its main() method the whole GUI end blows up.

ParamView pseudo code :

The same as before happens except the runProc() method is called from the AWT-EventQueue-0 thread.

The run() method in the invokeLater() method is NOT called, therefore the constructor for the Monitor class is NOT called and the code continues processing. When the code reaches a point where it wants to print a message in the Monitor JFrame - the variable 'mon' has not been initialised and the application throws a NullPointerException. Interestingly enough this JFrame also shows exceptions when they occur and now the Monitor constructor is called.

Why does the AWT-EventQueue delay displaying this frame? How come it does not run when the 'mon' variable is called the first time, but does the second?

If I change the runProc() method to include the following :

The if() statement catch the AWT-EventQueue-0 thread and creates the Monitor outside the invokeLater code. Both the Monitor class and Screen class are invoked however they show as two grey boxes.

This is doing my head in, any help would be appreciated.

Many thanks,

What's that smell? I think this tiny ad may have stepped in something.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic