Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By Lil_Aziz1

Thread: windowClosed() vs windowClosing()

  1. #1
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default windowClosed() vs windowClosing()

    windowClosed(): After window has closed.
    windowClosing(): The process of being closed.

    Which one is preferred for saving a state of an object using Properties? Does it matter? If one does windowClosing(), does he have to do setDefaultCloseOperation(WindowConstantsDO_NOTHING _ON_CLOSE) and then do either dispose() or System.exit(0)? That engenders another question: Is it better to do dispose(), System.exit(0), or both? There is only 1 frame in this app.

    both as in:
    Java Code:
    dispose();
    System.exit(0);
    Thanks in advance!
    vy12021 likes this.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hmm, I just go through the documentation, windowClosed is "Invoked when a window has been closed as the result of calling dispose on the window." So that at the time of it's calling the window is gone. But windowClosing is called when it's gone, but well before it actually is. So my point it use of windowClosed.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default

    If you System.exit(0) from windowClosing, any code in windowClosed will NOT be executed.

    db

  4. #4
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    So should I do windowClosed() or windowClosing()? windowClosed() sounds like less work, but I want efficiency.
    Last edited by Lil_Aziz1; 08-05-2010 at 02:42 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  5. #5
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Okay windowClosed() sucks. The only way windowClosed() event is executed is when frame.setDefaultCloseOperation(javax.swing.JFrame. DISPOSE_ON_CLOSE) or you do dispose()

    EDIT:

    Quote Originally Posted by Eranga
    windowClosed is "Invoked when a window has been closed as the result of calling dispose on the window."
    Should've listened lol. Just saw this. Sorry Eranga

    This works for me:

    frame.setDefaultCloseOperation(javax.swing.JFrame. EXIT_ON_CLOSE); + overriding windowClosing() event. No need to do dispose() or System.exit(0)
    Last edited by Lil_Aziz1; 08-05-2010 at 04:23 AM.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Darryl.Burke View Post
    If you System.exit(0) from windowClosing, any code in windowClosed will NOT be executed.

    db
    By mistake most of the people stuck on this unreachable code segment.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Lil_Aziz1 View Post
    Okay windowClosed() sucks. The only way windowClosed() event is executed is when frame.setDefaultCloseOperation(javax.swing.JFrame. DISPOSE_ON_CLOSE) or you do dispose()

    EDIT:



    Should've listened lol. Just saw this. Sorry Eranga

    This works for me:

    frame.setDefaultCloseOperation(javax.swing.JFrame. EXIT_ON_CLOSE); + overriding windowClosing() event. No need to do dispose() or System.exit(0)
    Yeah, avoiding dispose() is the most effective way to use in.

Posting Permissions

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