Reputation: 2397
I have a small game in which one window opening the other when the game over. I want to close only the game over window.
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
But this closes the both windows. How to close only the second window?
Upvotes: 1
Views: 695
Reputation: 2201
It can be closed from the game over window itself by
this.dispose();
or hidden by
this.setVisible(false);
You can also change the closing behavior with (assuming a JDialog where the default is HIDE_ON_CLOSE
)
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
If you need to close it from the parent JFrame
, dont use this
, but instead target the object
gameOverDialog.dispose();
Upvotes: 5