The best option is not to open and close multiple windows. If you have to do this, better to have one main window be the JFrame and open and close dialog windows such as JDialogs.