• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stuck in a loop after setVisible false to JFrame

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm tryiing to write a program for ordering movie tickets.
I'm stuck on the first phase
The problem is when I want to set JFrame visible to false, the programs doesnt continue running.
It's more strange that when I'm printing something in the loop that checks the wndow visiblilty it continue running and actually works.
Another strage thing is that in debugmode it also works fine.
So the problem occues only when tring to run the program not in Debug mode and without a print in the loop.
Any help will be appriciated
Here are the classes codes :


 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that when you call setVisible() the displaying of the frame is done on the EDT (Event Dispatch Thread) and not the main thread so the frame may not be displayed yet when the method returns. You then enter your while loop and so the while loop immediately fails and you dispose of the frame. It works in debug because as you step through the lines manually there is time for the Frame to be displayed before you execute the while loop check. Your second loop may work because the relevant code has already been loaded and executed once and so completes quickly enough second time around for the while loop check to succeed. But this may vary for multiple runs of the code or if running it on another machine.

If you want to display a GUI and get the entered value when the GUI closes you are better off using a modal JDialog.
 
Eitan Shaked
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
Thanks for the fast reply..
But, if you were right, then the print that comes after the shile should have print what inside of it, but it doesnt go there.. It looks like the program is stil running and hangs.
I would like you to show an example of how to use it correctly in JDialog.
Thanks again
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
selectedMovie is an empty string if the while loop doesn't run and so how would you tell if it was printing anything or not? Try initialising it a "TEST".

To find out how to use JDialog check out the Java tutorials.
 
Eitan Shaked
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Printing messages really helped..
But the problem was solved in other way..
To overcome this issue I called repaint() function, which actually waits till all components are drawn. After that everything works great
Thanks for the help though, I will definitely use your forum , and will share my knowledge in other programming languages ( which I'm well known with )
Thanks!
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
reply
    Bookmark Topic Watch Topic
  • New Topic