CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 1999

    Rejecting the EXIT of a Java app

    I know this is simple, but I just can't find the solution (and Code Guru's search feature seems to be broken as clicking on it produces an endless wait)

    I want the ability to reject the exiting of an app. When the user exists, I want to display a message that allows the user to cancel the exit request.

    I have had no luck. First off, this has such vague, general words that search results produce little more than completely unrelated topics. Other results advise listening for the windowClosing() event provided by WindowAdapter / WindowListener. This fails for 2 reasons:

    1) Closing the app with "System.exit( X )" does not result in this event being fired.

    2) windowClosing() does not allow you to reject the closing. All it does is tell you that it happened (when it even bothers to tell you that), but there is no way to reject it.

    What do I need to do?
    Why are the "tolerant" so easy to offend?

  2. #2
    Join Date
    Aug 1999

    Re: Rejecting the EXIT of a Java app

    Finally found the solution:


    Basically in the windowClosing() event you don't reject the closing you just change how the app handles a closing request. This ends up allowing you to either accept or reject. So you'd have something similar to this:

        public void windowClosing() {
            final int ret = JOptionPane.showConfirmDialog(this, "Are you sure you want to quit?",
            if (ret == JOptionPane.YES_OPTION) {
            else {
    Why are the "tolerant" so easy to offend?

Tags for this Thread

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.