Results 1 to 5 of 5
  1. #1
    jobud9 is offline Member
    Join Date
    Dec 2011
    Posts
    34
    Rep Power
    0

    Default do something on frame exit

    I need to change a boolean when the exit event is called.. any way to do that?

  2. #2
    stevenfriz is offline Member
    Join Date
    Feb 2012
    Posts
    28
    Rep Power
    0

    Default Re: do something on frame exit

    I'm not 100% sure, but I think you would implement a Container Listener for this type of situation.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: do something on frame exit

    If this is AWT/Swing, WindowListener#windowClosing / windowClosed.

    Please be more specific with your questions, and post in the appropriate section of the forums. There are separate sections for AWT/Swing and SWT/JFace.

    It does rather look like what you really need (again, if this is Swing) is a modal JDialog.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    JG4m3r is offline Member
    Join Date
    Mar 2012
    Posts
    16
    Rep Power
    0

    Default Re: do something on frame exit

    Java Code:
    Boolean b = new Boolean(true);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    //Set up a listener that calls the method closeMyFrame() when X is pressed
    
    public void closeMyFrame(){
         b = false;
         System.exit(0);
    }

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default Re: do something on frame exit

    Quote Originally Posted by JG4m3r View Post
    Java Code:
    Boolean b = new Boolean(true);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    //Set up a listener that calls the method closeMyFrame() when X is pressed
    
    public void closeMyFrame(){
         b = false;
         System.exit(0);
    }
    1. Where did the question state your assumption, that the program should terminate when the frame is closed?
    2. Even if that is assumed, what do you gain by setting the value of a variable that is about to be lost on VM exit?
    3. Even if that made sense, what would be wrong with the JFrame's initial default close operation of HIDE_ON_CLOSE? Why DO_NOTHING_ON_CLOSE?

    4. and most important: Don't try to spoonfeed. In the best case, it passively deprives the questioner of a learning opportunity. In the worst case (and this is one of those) it's totally misleading and actively detracts from the learning experience.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 7
    Last Post: 04-01-2012, 05:11 AM
  2. Replies: 4
    Last Post: 01-18-2011, 09:22 AM
  3. Java slave Frame access to its owner main frame problem
    By cagdaseckin in forum New To Java
    Replies: 0
    Last Post: 12-10-2010, 11:40 AM
  4. Replies: 7
    Last Post: 11-02-2009, 07:31 PM
  5. How to exit the program by typing "exit"?
    By Laythe in forum New To Java
    Replies: 6
    Last Post: 08-19-2009, 09:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •