Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

opening multiple frames in a loop

 
Ashish Sarin
author
Ranch Hand
Pie
Posts: 444
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using a for loop to create a JFrame. How can I make the program wait for the first window to close before opening the other one ?? I mean in what way I can make the for loop wait to excute the loop again.

regards,
Ashish Sarin
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure a for loop is going to be the best option for what you are trying to do. Which leads me to my next question...Why are you needing to pause between opening windows in a for loop?? What is the purpose of waiting for the window to close? Answering these questions might lead to a better solution than the one you are trying to implement.
 
Ashish Sarin
author
Ranch Hand
Pie
Posts: 444
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to make a sequence of updates lets say. Each sequence has a different UI (which is dynamically generated from a method called from the for loop itself).
 
Ashish Sarin
author
Ranch Hand
Pie
Posts: 444
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not pausing before the opening window. I open one window then I want the second window to open ONLY after I close the first window. This isnt happening in the current case.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds to me like you are creating some sort of a "wizard" where you might have a next button, or in your case, a close button that activates the next part of the wizard.

You can't really pause a for loop. What you might do is add a windowlistener to your frames and on the windowsClosing or windowClosed events, generate your next JFrame (basically, just do whatever you were doing in your for loop, but do it in the windowClosing event method. Does that makes sense? Let me create some rough code, but it may be way off without really understanding your situation:



Does this help?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a for-loop, but a timer seems to work OK...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic