Results 1 to 5 of 5

Thread: Overriding close operation

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Overriding close operation

    I have a class that extends JFrame, and I am adding a WindowListener in the constructor like this:
    Code:
    //...
    this.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent we)
      {
        if (exit())  System.exit(0);
      }
    });
    //...
    where exit() throws up a confirmDialog and returns whether or not the user clicks the Yes button. The problem is, when the user clicks the No button, the window disappears, and the app is stil running in the background. So how do I keep the window up and visible?

    Thanks
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    A simple option is to make sure the window is visible by using an else clause, something like this:

    Code:
    //...
    this.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent we)
      {
        if (exit())  System.exit(0);
        else this.setVisible(true);
      }
    });
    //...
    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091


    Sorry, it still disappears for some reason.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    What on earth is the exit() function? If it's a custom function you have made, which is what I suspect, try changing its name to something like ConfirmExit. I think the name exit() might be playing mischief.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5
    VirtuallyVB
    Guest
    Check out
    public void setDefaultCloseOperation(int operation)
    for JFrame.

    I think you want something like:
    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    perhaps right before
    this.addWindowListener(new WindowAdapter()...

Posting Permissions

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



Click Here to Expand Forum to Full Width