JFrame - EXIT_ON_CLOSE

Discussion in 'Web Design & Programming' started by harrack52, Sep 13, 2004.

  1. harrack52

    harrack52 Supreme Geek

    Likes Received:
    5
    Trophy Points:
    0
    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.
     
  2. harrack52

    harrack52 Supreme Geek

    Likes Received:
    5
    Trophy Points:
    0
    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 :)
     
  3. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    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
     
  4. harrack52

    harrack52 Supreme Geek

    Likes Received:
    5
    Trophy Points:
    0
    You'll see all the different Listeners once you get into the graphic environment.
     

Share This Page