How to do a last command before closing JFrame?

Hi, I'm working on a GUI, and there is a TextArea, which is set to the System.out.print commands, and i'd like it to save into a file, when i close the jframe, by pressing the X in the upper right corner.
I've made a working saving void, the only problem is: - How can i do it so that i can run a command (the saving) before the JFrame exits, and the whole program closes?
I've tried to use the tutorial here
http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
But it is either requiring me to make my class file into abstract which gives me other errors, or nothing would happen when i press the X.
I have the needed stuff imported, i've tried following the example java file on that page as i could, i still cannot be able to do it. I've also tried to compile the example file itself, there were no errors, but when i tried to run it, it closed with some errors.
Any ideas?

By using the WIndowAdapter class, you can avoid having to add empty methods for WindowListener. Try this on your JFrame:yourJFrame.addWindowListener (new WindowAdapter () {
    public void windowClosing (WindowEvent e) {
        System.out.println("Window closing");
});It's the same as adding any other Listener.
db

Similar Messages

  • All i need to know if how to turn on "warn me before closing multiple tabs"

    how do i turn on "warn me before closing multiple tabs"? i like this feature and accidentally turned it off and now, since it does not warn me before closing multiple tabs, i need to know how to turn it back on

    Are you reopening the pages automatically on the next start?
    Tools > Options > General > Startup: "When Firefox Starts": "Show my windows and tabs from last time"

  • How to Run Operating System Command Before/After Message Processing SAP PI

    Hi,
    We are trying to execute multiple commands via "Operating System Command Before/After Message Processing".
    When we use single command say for example cp or mv (copy or move) the commands get executed fine.
    eg: cp %F /var/opt/data/outbound/Test/Dummy.txt 
    /this works fine/
    when we club commands together or try to redirect the outputs of commands, none of the commands get executed.
    eg:
    cp %F /var/opt/data/outbound/Test/Dummy.txt ; rm %F
    or
    wc -l %F > /var/opt/data/outbound/Test/Dummy.txt
    Is it possible to execute multiple commands or redirect the output  of commands without using a shell script? The PI server we are working on iis hosted on UNIX environment.

    Hi Harleen,
    try like this
    cp %F /var/opt/data/outbound/Test/Dummy.txt ; rm %F
    instead of semicolon try this
    (1) &
    command1 & command2
    Execute Command1 and then execute Command2
    (2) &&
    command1 && command2
    Runs the command2 only when command1 doesn't Complete successfully
    (3) ||
    command1 || command2
    Runs the second command if the first command had an error
    (4) ()
    (command1 || command2) || (command3 & command4)
    Defines the order in which commands are to be executed
    Regards
    Suraj

  • How to send a warning message before closing soft via X of the title bar

    With labview 8.2:
    I would like to send a warning message before closing my soft when the user press the "X" of the title bar. Is it possible to do that without a Windows dll?
    Thanks a lot,
    Daniel.

    Gerd,
    I think a filter event for 'Panel close?' is more appropriate because you have the possibility to cancel the event or continue the event.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • How to suppress the Save Dialog before closing the form?

    Dear all,
    I created a form which will open a data connection on a button click.
    I catch the error on failure and code to close my form by app.execMenuItem("Close");
    but a Save Dialog will appear before I can close it.
    (may be because I have done something on opening the form),
    is it able to suppress it? Or simply cannot?
    Best Rgds.

    but it seems that after event.target.closeDoc(true);
    the codes that follow will continue to run,
    but this doesn't happen if I use app.execMenuItem("Close");
    I already include the closeDoc inside the try catch.

  • TS4006 is there a way to undo the "Erase" command before the deletion starts?

    is there a way to undo the "Erase" command before the deletion starts while the phone is turned off.  In my case the erase is pending the phone being turned on.  Now that I have found the phone, I don't want the deletion to happen.  How can I undo the command before turning on the iPhone?

    There's no way to block the remote wipe.  But once it's been wiped, you can perform a restore from your backup on either icloud or itunes.

  • How do I set Safari to prompt before closing multiple tabs OR reopen all of the closed tabs when when I relaunch the application?  The "Reopen all windows from last session" is unselectable.

    How do I set Safari to prompt before closing multiple tabs OR reopen all of the closed tabs when when I relaunch the application?  The "Reopen all windows from last session" is unselectable.

    It would seem if your choose "Show my windows and tabs from last time" '''''and''''',
    *when you last closed Firefox, you had no web site open (just a blank tab), that it would open just that blank tab
    *when you last closed Firefox, you had one or more tabs/web site open, that would allow you to "Restore Previous Session"
    #Have you tried that?
    #If so, what is happening in each circumstance when you reopen Firefox?
    '''Restore Previous Session'''<br />
    Open tabs are automatically saved when closing Firefox beginning in Firefox 4. To open your last session, after Firefox starts, click History > Restore Previous Session. For this to work
    #You must be remembering history (Options > Privacy > Remember my browsing history).
    #*See [https://support.mozilla.com/en-US/kb/Options%20window%20-%20Privacy%20panel Options window-Privacy panel]
    #You must not be using Private Browsing or permanent Private Browsing
    #*See [https://support.mozilla.com/en-US/kb/Private%20Browsing Private Browsing]
    #You must not use Clear Recent History or Clear history when Firefox closes
    #*See [https://support.mozilla.com/en-US/kb/Clear%20Recent%20History Clear Recent History]
    #*See [https://support.mozilla.com/en-US/kb/Options%20window%20-%20Privacy%20panel Options window-Privacy panel]
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You need to update some plug-ins:
    *Plug-in check: https://www-trunk.stage.mozilla.com/en-US/plugincheck/
    *Adobe PDF Plug-In For Firefox and Netscape: [https://support.mozilla.com/en-US/kb/Using%20the%20Adobe%20Reader%20plugin%20with%20Firefox#w_installing-and-updating-adobe-reader Installing/Updating Adobe Reader in Firefox]

  • How do I move a group of tabs before closing a window?

    I recently lost all my custom settings on Firefox after an aggressive tech support person "cleaned" my browser settings. When this happened, I lost the ability to move my open tabs to a new group before closing the window they were in.
    Previously, when I had multiple windows open, and I initiated an "Exit" or "Close" command on one of the open windows, 2 things happened:
    (1) First I received a warning message asking me if I wanted to close the window
    (2) Then I received a second warning message asking me if I wanted to move my tabs before closing the window.
    Now, I only receive the 1st message, and I am no longer offered the option of moving my tabs to a new window before closing the current window.
    I've tested this both with and without the Tabs Group Manager which I was using prior to the time my browser was "cleaned", and I still have not found a way to restore this missing feature.
    Unfortunately, I don't know if this feature/option is:
    -- provided as a default in Firefox
    -- a customizable feature in Firefox, or
    -- a feature in a Firefox add-on.
    Can anyone tell me where/how to restore this option to move a group of tabs before closing a window?
    Thanks,
    Metta

    Thank you, guigs2, for your feedback, and my apologies for the confusion. After rereading my question, I realize I made a couple of typos in my original help request which cannot now be corrected. Specifically, the 2nd sentence in the first paragraph should have read:
    "I lost the ability to move GROUPS of open tabs to a new WINDOW before closing the window they were in."
    This means that, as far as I can tell, neither of your plugin recommendations applies:
    -- Apparently, Tab Mix Plus only applies to manipulating tabs WITHIN the existing window and, unless I am missing something, I did not see any reference to the option I'm looking for -- specifically, an automatic prompt offering to move groups of tabs to a new window before closing the existing window.
    -- Unfortunately, the other plugin you mentioned (Tag Cloud) appears to be non-functional in the current version of Firefox, based on the most recent user reviews.
    In light of this, I will consider the possibility of resubmitting my question with the typos corrected -- and, in the meantime, if there is any additional feedback that you (or anyone else) can offer, I would be most grateful!

  • The last few days I have been constantly saving my file. About an hour ago I opened my file and the most recent work wasn't saved even though I'm sure I saved it before closing. What can I do? Also, when I have tried to email it to myself as a backup, the

    The last few days I have been constantly saving my file. A couple of hours ago I renamed the file and then reopened my file a little while later, but the most recent work wasn't saved even though I'm sure I saved it before closing. What can I do? Also, when I have tried to email it to myself as a backup, the fields aren't populated when I open it up. Fyi, I have the free subscription.

    Hi Constance,
    As i understand your changes in the pdf were not saved...Are you still facing this issue?
    Regards,
    Rahul

  • How do I stop pop up that asks me, Do you want to save changes to doc... before closing? I have made no changes only printed the file. Using Adobe Reader DC, Windows 7 64 bit.

    How do I stop pop up that asks me, Do you want to save changes to doc... before closing? I have made no changes only printed the file. Using Adobe Reader DC, Windows 7 64 bit.
    This is very annoying and we need this stopped as we have made no changes to any of the adobe files. Please advise how to do this.
    Customer Service DCC

    I first tried the version without the deflated stream (so everything uncompressed) against the online repair tool to check/analyse it @ https://www.pdf-tools.com/osa/repair.aspx
    And it says no error found, but the reader still want to save it when closing so i still had no clue at this point.
    Fortunately, i finally found what was wrong with my generated PDF.
    In my xref table, each object reference was not end by a full EOL, i only did put a newline char.
    Now i have "carriage return" "newline" which is the full EOL and the reader is happy and close the file silently.
    As suspected i did not follow correctly the specs on xref table
    Now i'll go and figure what i did wrong with the deflate filter
    Thanks for your help.

  • How to Identify Last  Command Issued by user??

    Hi Everybody,
    I need to create a form in which the current state of the form depends upon the last command issued by the user.
    Suppose if user clicks 'delete record' or 'insert record' or 'enter-query' or something else.
    So, how to identify the last event executed by the user.
    Any suggestions...
    Thx in advance,
    Raj

    You can write something into a Form parameter in the POST-INSERT/UPDATE/Query triggers.
    Then you can check the value of this parameter when needed.

  • HT2693 i am downloading a software update, but at the last moment before it finishes, it says in order to continue, please close the following application: safari, and the application is closed, what do they mean, and what should i do?

    i am downloading a software update, but at the last moment before it finishes, it says in order to continue, please close the following application: safari, and the application is closed, what do they mean, and what should i do?

    You should close safari.

  • TS4006 How do you find where your Iphone was last located before powering off?

    How do you find where your Iphone was last located before powering off?

    Hi Mr. Wayans,
    Here is a support article with the information you are looking for:
    http://support.apple.com/kb/PH2698
    Cheers,
    GB

  • How do I restore from last backup  before IOS upgrade?

    How can I restore from last backup before IOS upgrade?

    You need to go into Settings > General > Reset > Erase all Content and Settings.
    Once done you will be back as though it is a new iPhone and you can setup from the iCloud backup.

  • Before closing down the machine, how can I close all the open programs?

    Now that the iMac automauically starts up with the programs in use when closing, I find that this is delaying my start.
    There must be a shortcut to close all the open programs before closing the machine.
    Kindly advise.

    If by 'closing' the machine you mean shutting it down, there is a checkbox in the Shutdown confirmation window which is preset to re-start all apps at startup which were open when the machine was shut down. Uncheck that item in the Shutdown confirmation window.
    Unfortunately you'll need to do that each time you shut the machine down.

Maybe you are looking for