I have swing apllication in which after password reset I want to take user to Login screen. For that I want to close all open windows and open Login window so that user can login with new credentials. Is there any class/method in java which can be used to close all windows?
System.exit() terminates whole application which i do not want.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
A word of caution: the array returned by that static method includes references to windows that are no longer visible or even displayable -- even windows that are no longer in scope. On all current Sun (Oracle?) JVMs a call to System.gc() removes those, but that behavior isn't mandated by the JLS nor the JVM spec. Code calling this method without first collecting garbage should preferably declare the array in a very limited scope so as not to hold on to references to windows that are no longer in use, thus preventing their collection. Alternatively, while looping over the array, any reference to a non-visible window could be set to null.
Joined: Jul 29, 2008
I think container.dispose() will dispose the frame from which it got call. In my application there might be no of windows are opened.
After resetting password from one window it should close all previous windows and open new window - LOGIN window. So user can process with new credentials as old credentials are not valid now. It is similar to change password og google or yahoo where user goes to login page after resetting his password.
Yes, that's right, but next time please UseCodeTags <-- link. I've added them for you this time.
I would just explicitly set the array variable to null after the loop (or let it fall out of scope) but there's no harm in setting individual elements to null if the array remains in scope a bit longer. Not that it helps in any way to have an empty array lying around.
One way of ensuring that the array isn't still in scope after the loop isThe variable window is local to the loop, and no copy is made of the array.
In case you're not familiar with that loop construct, read about it here.
Joined: Jul 29, 2008
Thanks allot Darryl!!
I will definitely take care of UseCodeTags from next time.
subject: Closing all open windows and opening new one