JFrame - EXIT_ON_CLOSE

harrack52

Supreme Geek
Not related to the web but this is the only programming forum so....here it is.

My problem is simple. Java related, of course.

I have a window (which herits from JFrame), and I'd like to output a message when the user clicks on the X at the top-right corner of the window, but I don't know how to handle that event. I'm guessing a method is called when that happens but it's only a guess. I've done it once before but really can't remember how it's done.

Any help is appreciated.
 
Ok I continued to look for an answer and found one :D

Before, I was "telling" the program to quit if the X was clicked:

setDefaultCloseOperation(3);
3 being the value of JFrame.EXIT_ON_CLOSE.

Instead, I used the value of JFrame.DISPOSE_ON_CLOSE and used a Listener (WindowListener) that calls the method windowClosed when a window is closed returning the value of the constant above.

Thanks anyway :)
 
hehe, cool! I don’t know any Java, so could help :) sorry! It could well come up on my course at uni so could be useful in the future! thanks
 
Back
Top