I have a little frame where I ask user & password. This frame will be opened clicking over a button in a main window.
Then I have two buttons: ok and cancel.
Maybe a cleaner way is just change the setDefaultCloseOperation from EXIT_ON_CLOSE to DISPOSE_ON_CLOSE :
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);