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.
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.
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).
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.
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: