Confirm Exit Dialogue Problem... Help!

Hey,
I am using this piece of code so that when i press the [X] button in the top right hand of my GUI, just before the app exits, it asks the user if they wish to exit.
But it does not quite work. If i click "yes" the app exits, and it does the same when i press "no"! :s
"ImageCreator" in the below code is the name of my application class.
I have tried replacing "ImageCreator" with "this" in the code below but i just get errors when i compile it.
Could someone please help me and show me how to get around this problem.
Thank you for your help! :)
Claire
x
    class WindowEventHandler extends WindowAdapter
        public void windowClosing(WindowEvent e)
            int exitQ = JOptionPane.YES_OPTION;
               exitQ = JOptionPane.showConfirmDialog(ImageCreator,
                                                 "Do you wish to exit?",
                                                 "Exit J.P.E.G.Suite?", JOptionPane.YES_NO_OPTION);
               if(exitQ == JOptionPane.YES_OPTION)
                       System.exit(0);
               else
    }

I would assume you used setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) because I have had this problem before. The thing is, this exits the application no matter what because you tell the app to exit after the window is closed. The trick is to use JFrame.DO_NOTHING_ON_CLOSE and exit the app in the window listener.
Note: <filename> means the currently open file
<application name> means the application name
public class SomeApplication extends JFrame
    public SomeApplication()
         //absolutely essential - we can implement the closure in our window listener
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
//insert GUI code here
        addWindowListener(new WindowAdapter()
            public void windowClosing(WindowEvent evt)
                 int result = JOptionPane.showConfirmDialog(this, "Do you want to save changes to <filename>?",
"<application name>", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
                 switch(result)
                     case JOptionPane.YES_OPTION:
                         save(); //your save method  which saves the document
                         System.exit(0);
                     case JOptionPane.NO_OPTION:
                         System.exit(0);
//insert GUI code here...
}Stephen

Similar Messages

  • EDI - IDoc - User Exit - Code - Problem - Help - Wanted

    Hi EDI Experts,
    I have extended ORDERS05 IDOC twice.
    ZVKSEG1 is the the segment under extended idoc ZVKORDRS05. This is for one partner.
    Z1DATESH01 is the segment under extended idoc Z1ORDER05. This is for another partner.
    I have completed the configuration thing in WE82 for both the extensions.
    Now the requirement is, whenever a PO is created for the first partner - 100290, the IDoc generated should contain the extra segment ZVKSEG1 and whenever PO is created for the second partner - 10099,the Idoc generated should contain the extrasegment Z1DATESH01.
    Using WE20, i have added the extended IDoc type in both the partner profiles under ORDERS message type.
    Now i've written the user exit for this using EXIT_SAPLEINM_002.
    tables: edidc.
    data: z_edidd like edidd occurs 0 with header line.
    data: y1dath01 like z1datesh01.
    data: yvkseg1 like zvkseg1.
    if edidc-rcvprn = '10099'.
    z_edidd[] = int_edidd[].
    loop at z_edidd.
    if z_edidd-segnam  = 'E1EDK01'.
    read table z_edidd  with key segnam  = 'Z1DATESH01'.
    if sy-subrc <> 0.
    y1dath01-DELDATE = sy-datum.
    clear z_edidd.
    z_Edidd-sdata = y1dath01.
    z_Edidd-segnam = 'Z1DATESH01'.
    append z_edidd.
    endif.
    endif.
    endloop.
    int_edidd[] = z_edidd[].
    elseif edidc-rcvprn = '100290'.
    z_edidd[] = int_edidd[].
    loop at z_edidd.
    if z_edidd-segnam  = 'E1EDK01'.
    read table z_edidd  with key segnam  = 'ZVKSEG1'.
    if sy-subrc <> 0.
    yvkseg1-name1 = 'ZVK Chemicals'.
    clear z_edidd.
    z_Edidd-sdata = yvkseg1.
    z_Edidd-segnam = 'ZVKSEG1'.
    append z_edidd.
    endif.
    endif.
    endloop.
    int_edidd[] = z_edidd[].
    endif.
    Could you please go through the code and tell me where did i go wrong. The extra segments are not being created for both the partners.
    I created PO using ME21n once for each vendor.
    Please help me out guys.
    Thanks,
    Matt

    I myself fixed this problem. I made use of XLFA1-LIFNR to manipulate the partner numbers.
    Thanks

  • My daughter has just bought me an iPad 2 from Dubai and set it all up for me but unfortunately the iMessage function doesn't seem to work. We keep getting messages,when trying to activate it, that there is a network connection problem - help!

    My daughter has just bought me an iPad 2 from Dubai and set it all up for me but unfortunately the iMessage function doesn't seem to work. We keep getting messages,when trying to activate it, that there is a network connection problem - help!

    Thank you both for your responses but my daughter was reassured by the salesman in the iStyle store (official Apple store in the UAE) that iMessages would work but conceded that FaceTime wouldn't. My iTunes account is registered in the uk and my daughter's iPhone has iMessages even though she bought it (and uses it) in Dubai. Can anyone else throw any light on this?

  • I couldn't log into my apple account on my iPad, then i couldn't unlock it resulting in it being disabled, however it's the same as my iPhones password, I then called apple, i was hung up on twice and they said it will cost £70 to fix THEIR problem, help?

    I couldn't log into my apple account on my iPad, then i couldn't unlock it resulting in it being disabled, however it's the same as my iPhones password, I then called apple, i was hung up on twice and they said it will cost £70 to fix THEIR problem, help?

    If you cannot remember the passcode, you will need to restore your device using the computer with which you last synced it. This allows you to reset your passcode and resync the data from the device (or restore from a backup).
    If you restore on a different computer that was never synced with the device, you will be able to unlock the device for use and remove the passcode, but your data will not be present.
    You may have to force iPad/iPod into Recovery Mode
    http://support.apple.com/kb/ht4097

  • I still use Aperture 2.1.4.  I need to export an image file with a CMYK profile.  Whereas a generic CMYK profile is listed in ColorSync Utility, it does not appear on the list of profiles in the edit portion of the export preset dialogue.  Help?

    I still use Aperture 2.1.4.  I need to export an image file with a CMYK profile.  Whereas a generic CMYK profile is listed in ColorSync Utility, it does not appear on the list of profiles in the edit portion of the export preset dialogue.  Help?  Is there some way to add the CMYK profile to the list of choices that are available in the export preset dialogue such that I can choose it?

    leonieDF
    Thanks for your response.  My profiles are located within color sync utility as you can see here:   
    These profiles do not respond to clicking and dragging.  Since they are all in one place, more or less, I'm reluctant to make further attempts to relocate them.  Accessing the CMYK profile is the first difficult experience I've encountered with this arrangement.  I have never needed the CMYK profile until recently, and that need has now past.  However, it remains a mystery to me as to why it does not appear with all the others on the menu of export choices in Aperture 2, or on the menu of profile assignment choices in the Preview application (where again all the other profiles are listed as choices).  I'm beginning to think my current set up will permit me to view an image that was created in CMYK space, but does not easily assign, or convert to that space.  I don't face these restrictions with all the others, so it remains a curious circumstance for me.  I anticipate upgrading my computer and software in the near future which might alleviate this issue altogether.  Again, many thanks for your attention to this matter.  The reach of this community is astounding.

  • IPad syncing problem - HELP!

    iPad sync problem - HELP!  I keep getting this message "...cannot be synced because there is not enough free space to hold all of the items in the iTunes library (additional ...space needed)"  and yet I seem to have plenty of space on the iPad.  This just started today.  I even tried deleting some things to make even more room, but it didn't help.  Any ideas??? 
    I was thinking of restoring, but I've never done it...  should I? 
    thank you!

    Hello florafromnv,
    Welcome to Apple Support Communities.
    The following article addresses how to resolve the issues related to this message:
    iOS: "Not enough free space" alert when trying to sync
    http://support.apple.com/kb/TS1503
    Regards,
    Jeff D.

  • MOVED: KT333 Ultra; fuzzy logic, 1.6xp overclocking problem help !!!!!

    This topic has been moved to Overclockers & Modding Corner.
    KT333 Ultra; fuzzy logic, 1.6xp overclocking problem help !!!!!

    Not that I am an expert o/c but here are some thoughts on the matter.
    My comments are based on my experiences of the KT3 Ultra2 which is basically the same as the Ultra version.
    This mobo does not have the ability to lock the PCI/AGP bus freely from the FSB. However, it does have dividers. At 133 a 1/4 divider kicks in. Above 152FSB the 1/5 divider works, so that at 166 the PCI & AGP buses will be back in sync. If you are o/c your cpu, don't go from 133 to 145, etc since you will be running the PCI/AGP buses further out of whack. Just go to either the mid 150's or to 166 in one jump. The other problem / issue relates to your cpu. From what you say you have one of the old Palominos which are not great o/c's. I would personally o/c your cpu from the BIOS rather than 'Fluffy Logic' which I would tend to stay away from. 
    With a 166FSB cpu a very stable o/c would be 175-177 beyond 180 gets decidedly tricky.
    Hope this helps

  • Itunes keeps closing as soon as i open it and states 'windows has detected a problem' HELP!!!!

    Help!! Itunes keeps closing straight away and message states 'windows has detected a problem' HELP ASAP PLEASE!!!!

    For general advice see Troubleshooting issues with iTunes for Windows updates.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    If you've already tried a complete uninstall and reinstall try opening iTunes in safe mode (hold down CTRL+SHIFT as you start iTunes) then going to Edit > Preferences > Store and turning off Show iTunes in the Cloud purchases. You may find iTunes will now start normally.
    tt2

  • I have installed photoshop elements 12. when I try use the editing features it said that i must login to Adobe to register the product. but each time i try to it said there is a problem. help the problem stated that the internet is not connected, but that

    i have installed photoshop elements 12.
    when I try use the editing features it said that i must login to Adobe to register the product.
    but each time i try to it said there is a problem.
    help
    the problem stated that the internet is not connected, but that is not the case.

    I had the same issue and I'm running Windows 7.  Tried working with technical support for several hours but they were no help.  They just had me doing the same things over and over, offering no real answers.  I finally got fed up and have decided to return my product for a full refund.

  • I can't install the itunes to my windows 7 X86 APPCRASH problem, help me guys

    i can't install the itunes to my windows 7 X86 APPCRASH problem, help me guys??  i don't know what to do..

    Why are you unable to install the iPod Updater? Are you getting an error message? Please be specific.
    Cheers!
    -Bryan

  • Camera (focus) problem - help?

    Duplicate post, please see: Camera (focus) problem - help?
    Message was edited by: Admin Moderator

    Warranty is valid only in country of original purchase. You have to return
    the iPhone to the US for evaluation. Either you return it personally or send
    it to a friend/relative/co-worker in the US to take into Apple. Apple will not
    accept international shipments for evaluation nor will Apple ship out of the
    country after repair/replacement.
    Have you tried the standard trouble shooting steps: restart, restore, restore
    as new iPhone?

  • After update iPhone4 to iOS6, its stuck, showing only USB to iTunes on the screen. What to do, how to solve problem, help

    after update iPhone4 to iOS6, its stuck, showing only USB to iTunes on the screen. What to do, how to solve problem, help 

    Connect your phone to iTunes on your computer like the diagram has indicated and restore the phone

  • Trying to print says " problem with adobe acrobat/reader exit try again help?

    I keep trying to print a document, which has been working up until today, it has to be in PDF format to print, but when I push print a box comes on the screen and it says "there is a problem with adobe acrobat/reader, please exit adobe acrobat/reader and try again. What do I do? Thank you

    Hi tanjam38435898,
    Please refer this thread Links as it seems relevant to your query : Re: Error Code 0:104
    hope that helps
    Regards,
    Rahul

  • Seeking help confirming a specific problem

    If you are operating in 10.6.2 or 10.6.3 and have the third-party application "Play Sound," please respond if you might be willing to try a couple things -- if you might be willing, I'll send details of what I find to be very odd behavior.

    Tom, Thanks, most people don't have any problems. But for some reason, in this part of Texas, there have been problems. Just trying to narrow the problem down, for a cause and then a cure.

  • Printer dialogue problem - Photoshop CS5

    The dialogue options for paper size and kind of paper all of a sudden does not show in the print dialog box.  I deleted and added by Epson 2200 printer, removed the com.adobe.CSX52Preferences.plist and installed the latest printer driver. If I change to Photoshop manages color, the options reappear, but when I return to Printer manages color, the color is not right.  I am using Epson lustre paper.  I am using Mac IOS X.6.8
    Please help me resolve this issue.
    Thanks.

    The short answer is yes, I still see the same problem after following your instructions.  First, after clicking ok the first time I chose [Print Settings], when I again chose [Print Settings] I got the inane "Because the printer does not exist" error message.  I plunged ahead nonetheless, choosing a different printer, allowing the software to digest that, then choosing the R2000 again, whereupon I was able to choose [Print Settings].  In the meantime, of course, the software had lost all the modifications I had made the first time through.  I made the same changes again, printed the file, saved it, and exited Photoshop.  I then reopened the same file in Photoshop, but it had lost all the changes I had made (twice) the previous time I had it open.
    I've found that if I open a file and choose print, I can select [Print Settings] without an error.  If I print it, then try to print it again, I get the error message on selecting [Print Settings].  If I instead open a different file and choose print, I can select [Print Settings] without getting the error message.  As long as it's the first time in the session (not sure if it's triggered by a lapse of time or closing and reopening the file), I can select [Print Settings] file after file without seeing the error message.  This is small consolation if the print job I'm doing is a bunch of reprints of the same file.
    Steve

Maybe you are looking for