Save on exit

Discussion in 'Java' started by raphfrk@netscape.net, Jul 12, 2006.

  1. Guest

    When a user clicks X on the window to exit, how do I set it up so that
    a function is executed before the window exits ? Basically, this is to
    give the user a "file not saved" warning before exiting.
     
    , Jul 12, 2006
    #1
    1. Advertising

  2. Andrew T. Guest

    wrote:
    > When a user clicks X on the window to exit, how do I set it up so that
    > a function is executed before the window exits ?


    See
    <file:///F:/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)>

    HTH

    Andrew T.
     
    Andrew T., Jul 12, 2006
    #2
    1. Advertising

  3. Moiristo Guest

    wrote:
    > When a user clicks X on the window to exit, how do I set it up so that
    > a function is executed before the window exits ? Basically, this is to
    > give the user a "file not saved" warning before exiting.
    >


    Create a WindowListener
     
    Moiristo, Jul 12, 2006
    #3
  4. Andrew T. Guest

    Andrew T. wrote:
    > wrote:
    > > When a user clicks X on the window to exit, how do I set it up so that
    > > a function is executed before the window exits ?

    >
    > See
    > <file:///F:/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)>


    Or.. (polite cough) if you don't happen to be at my place, you might
    try..
    <http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)>

    Andrew T.
     
    Andrew T., Jul 12, 2006
    #4
  5. Oliver Wong Guest

    <> wrote in message
    news:...
    > When a user clicks X on the window to exit, how do I set it up so that
    > a function is executed before the window exits ? Basically, this is to
    > give the user a "file not saved" warning before exiting.


    Use a Window Listener to listen for the WindowClosing or WindowClosed
    event:
    http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/WindowListener.html

    - Oliver
     
    Oliver Wong, Jul 12, 2006
    #5
  6. Andrew T. Guest

    Uggh.. it was only after reading the replies of moiristo and Oliver
    that I realised I had misunderstood your question.

    Andrew T.
     
    Andrew T., Jul 12, 2006
    #6
  7. In article <>,
    wrote:

    > When a user clicks X on the window to exit, how do I set it up so that
    > a function is executed before the window exits ? Basically, this is to
    > give the user a "file not saved" warning before exiting.


    First, call this:

    myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    Then add a WindowListener to your frame and implement its windowClosed
    method. In that method is where you see if you need to save and respond
    appropriately.

    FWIW, you should probably go through the Swing tutorial Sun offers,
    since it covers relatively common topics like this. And you may also
    want to find the comp.lang.java.gui group, which is a better place to
    post GUI-related queries.

    = Steve =
    --
    Steve W. Jackson
    Montgomery, Alabama
     
    Steve W. Jackson, Jul 12, 2006
    #7
  8. Guest

    Steve W. Jackson wrote:
    > First, call this:
    >
    > myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    >


    Thanks, I just wanted to prevent people from closing without having to
    save. Now, the menu "quit" option must be used to exit and I can put
    the options on that.
     
    , Jul 14, 2006
    #8
  9. In article <>,
    wrote:

    > Steve W. Jackson wrote:
    > > First, call this:
    > >
    > > myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    > >

    >
    > Thanks, I just wanted to prevent people from closing without having to
    > save. Now, the menu "quit" option must be used to exit and I can put
    > the options on that.


    A well-behaved (make that "friendlier") application would still have a
    listener that would simply invoke the "quit" item you refer to, so that
    its action gets to the same code.
    --
    Steve W. Jackson
    Montgomery, Alabama
     
    Steve W. Jackson, Jul 14, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,975
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. Joe Smith
    Replies:
    4
    Views:
    66,086
    sandeep1976
    Nov 8, 2006
  3. Replies:
    2
    Views:
    493
    Jeff Epler
    May 31, 2005
  4. QQ
    Replies:
    5
    Views:
    548
    Jonathan Adams
    May 10, 2005
  5. Mel
    Replies:
    10
    Views:
    3,212
    Sailaja Appi
    Feb 13, 2009
Loading...

Share This Page