This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 :
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.
Joined: Dec 01, 2012
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.
Joined: Aug 07, 2007
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.
Joined: Dec 01, 2012
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 )