Executing code on EXIT_ON_CLOSE

I was wondering how you execute code when a JFrame closes using the X button (ie, without using a menu). Because you don't attach an ActionListener to it, I am unsure as to where I would place code that I would like to execute before the program exits.
Thanks

add a WindowListener to the JFrame; windowClosing() will be called when the X is clicked (setDefaultAction is more or less just a convenience method for this)

Similar Messages

  • The request to execute code in the sandbox failed

    I have developed a webpart for a client which is hosted on
    O365.
    While saving the webpart properties I am Getting the error"Web Part Error: The request to execute code in the sandbox failed."
    The same web part works on a different O365 site perfectly fine.

    Try below article
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/70b13a7f-c9f8-4bf9-8229-670472959e60/web-part-error-sandboxed-code-execution-request-failed?forum=sharepointdevelopmentprevious

  • It is possible to programmatically disable the "Executing Code Modules in an External Instance of CVI" feature?

    It is possible to programmatically disable the "Executing Code Modules in an External Instance of CVI" feature within a CVI project?
    I know how to do it manually (Configure > Adapters... > Adapter Configuration).
    Thanks in advance,
    --M

    Yes. TestStand 2.0 added the Engine.CVIAdapter_ExecuteStepsInCVI property.

  • Executing code in form of String object

    hi to all,
    I don't know if it's the right place to ask such a question, but at least, I can try my chance :)
    Can I execute code originally written in a text area (JTextArea) (i.e. in form of a String object) as if it was code already embedded in the code flow ??

    There are several solutions.
    As suggested above use Runtime.exec() to compile it. You can do this either by having the user enter the entire class or by having the enter only a portion which you then wrap (they write a method, or some rules in a method, etc.)
    There is a VM/version specific interface that allows you to compile without Runtime.exec() . You can search the site for examples of this.
    You can also use one of the java embeddable languages if you just what 'code' rather than supporting the entire java language.....search the following page for "Scripting"...
    http://flp.cs.tu-berlin.de/~tolk/vmlanguages.html

  • Adf valueChangeListener autosubmit=true, execute code after update model

    Hello.
    I'm working with the valueChangeListener and autosubmit="true". I'll try to explain my situation
    with an example.
    jsp:
    <af:form>
         <af:panelForm>
              <af:inputText
                   id="value1"
                   label="Value1"
                   value="#{index.myObject.value1}"
                   autoSubmit="true"
                   valueChangeListener="#{index.changeListener1}"/>
              <af:inputText
                   id="value2"
                   label="Value2"
                   value="#{index.myObject.value2}"/>
         </af:panelForm>
    </af:form>
    backing:
    public class Index {
        private MyObject myObject;
        public Index() {
            myObject = new MyObject();
        public void changeListener1(ValueChangeEvent valueChangeEvent){
              doSomethingWithMyObject(myObject);
        // ... get/set of myObject
    MyObject:
    public class MyObject {
        private String value1;
        private String value2;
        public MyObject() {}
         //getters/setters...
    }In the line doSomethingWithMyObject(myObject) i need myObject with the actual values in the user form.
    in the example above, the first time the page is rendered and shows the inputs
    if the user captures something in the 1st input and then hits the tab to go to the other input
    the valueChangeEvent is fired, and the code in "index.changeListener1" executed, but at this moment
    the model (myObject) hasn't been updated with the data that the user entered (Validation Phase).
    So i need a way to execute my code called from the "valueChangeEvent" but after the model has been updated
    Some notes about my problem:
         - The doSomethingWithMyObject(myObject) could update data in myObject
         - About binding="#{x.y}":
         I know i can use the binding attribute in the tag <af:inputText binding="#{x.y}"> and then in the code of
         the changelistener the binded component always have the most recent value from the user,
         but i cant' use that, the method needs a MyObject instance.
         - I don't think create a new instance of MyObject and populate it every time the event fires is a good way
         - doSomethingWithMyObject" is a black box, so i don't know what is going to do with myObject
         - In my problem there are more than 2 inputs there will be N components M listeners.
    What I'm trying:
         PhaseListener:
         I have been implementing a solution with a PhaseListener like
         public void afterPhase(PhaseEvent phaseEvent) {
              // just after UPDATE_MODEL_VALUES phase
              FacesContext f = FacesContext.getCurrentInstance();
            Index i = (Index) f.getApplication().createValueBinding("#{index}").getValue(f);
              // at this point the model is updated
              doSomethingWithMyObject(i.getMyObject);
         public PhaseId getPhaseId() {
            return PhaseId.UPDATE_MODEL_VALUES;
              this works but i don't know if this is the answer according to this post (unanswered at this time):
              http://forums.oracle.com/forums/thread.jspa?threadID=611643
         says something about that PhaseListener is not thread safe and blocks the application with more
         than 1 user.
         A wrapper:
         using the controls binded to the backing
         public class Index {
              private MyObject myObject;
              private CoreInputText inputValue1;
              private CoreInputText inputValue2;
              //listener
              //getters/setters
         }     make a wraper like
         public class MyObjectW {
             private Index index; // wrap the backing index
             public MyObjectW(Index index) {
                 this.index = index;
             public String getValue1(){
                 return (String) index.getInputValue1().getValue();
             public String getValue2(){
                 return (String) index.getInputValue2().getValue();
             public void setValue1(Object v){
                 index.getInputValue1().setValue(v);
             public void setValue2(Object v){
                 index.getInputValue2().setValue(v);
        }and then call in the index backing:
    doSomethingWithMyObject( new MyObjectW(this)); so it will access to the most actual values from user at the valueChangeEvent
    But i really would like some way to execute my code called from the "valueChangeEvent" but after the model has been updated
    so i dont need to wrap or implement PhaseListener
    what do you think, what do you suggest, have any solution or a way to do what I'm trying?
    thank you for your help...
    Message was edited by:
    akanewsted

    Hello Frank, thanks for the response.
    When you say
    "If you need an updated object in this listener then you can update it from the value change listener as well"
    you mean i can update the object by myself with the value from getNewValue()? or is there another way
    to call to update the models at this time ?
    I know i have the methods "getOldValue()" and "getNewValue()" in the "ValueChangeEvent" but what if i need
    the actual value from the user in other control than the one that fires the event
    example
    Two inputs:
    in the input1 the user enters some data
    in the input2 when some data is entered it fires valueChangeListener (autosubmit=true)
    in that case what if i need the value the user just entered in the input1 in the valueChangeListener of
    the input2.
    In general the app I'm working must do:
    dynamically generate the controls in the form (inputs, selects etc)
    Attach the control values to a model ( <af:inputText value=#{model.x}"/>
    sometimes execute some script when a value change in a control (valueChangeListener)
    those scripts uses the model (and needs to be an updated model)
              script = " if (value2 = 'xyz') then value1='abc'; return true;";
    if the model is not updated
    the script will use old values and will be wrong
    or if the script change some value in the model, when the update model phase occurs the value from
    the script is lost.
    that's why i need to work directly with the model and not the values in the ValueChangeEvent
    Is there a way to use something like an action in the change of a control value?
    that way the code will execute in the invoke application phase, can this be done ?
    how i can execute code in the invoke application when a valueChangeEvent occurs ?
    hope this help to explain more my situation.
    Thank you for your help and time.

  • Java Comiler - How to find out the Number of lines of Executable code

    Hello,
    Is there any option we have or could have to get the "Number of Lines of Executable Code" while we run the java compiler?
    Technically Java is an interpreter. So in case the term is incorrect, please excuse me.
    Since the compiler anyway traverses through the Java files, it is easy and correct to get the number from the compiler rather than having any external tool calculating the same.
    It should remove the comments, blank lines and take care of java single sentence written in multiple lines.
    Any suggestions or help is highly appreciated.
    regards,
    Sabyasachi

    How many lines of code are there in this program?
    public class sabre20110211 {public static void main(String[] args) {for (int i = 0; i < 10; i++)System.out.println(i);}}And how many in this program?
    public
            class
            sabre20110211
        public
                static
                void
                main(
                String[]
                args
            for
                    (int i = 0;
            i < 10;
            i++
                System.out.println(i);
    }

  • Resource-only DLL does not contain executable code

    A resource-only DLL does not contain executable code. Since
    LoadLibrary (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175.aspx) attempts to call the entry point before returning, it will fail for resource-only DLLs. Instead, you should call
    LoadLibraryEx (http://msdn.microsoft.com/en-us/library/windows/desktop/ms684179.aspx) passing a
    LOAD_LIBRARY_AS_DATAFILE, LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE, or
    LOAD_LIBRARY_AS_IMAGE_RESOURCE flag, to load a resource-only DLL. This prevents to loader from attempting to call the entry point.

    Hello,
    Just check if there is space in the front of these numeric values or some garbage value...if there is... then it may not be able to pad it up with zero and hence the issue...check in R/3 about how these values are stored...you can remove the space from the front and change it in PSA...and then load but first do the analysis of the source system and see why its coming up wrong.
    Regards
    Ajeeet

  • Executing code in NetBeans 3.5.1

    Hi,
    I've been using my own custom Ant scripts within NetBeans to compile code, generate various descriptors and create archive files. I really like using Ant; the only reason I even use an IDE is for editting--it's nice having its spell checking functionality, etc. However, to execute and debug code, I go straight to the command prompt to run my jar. But now I'd like to take the next step: execute and debug un-jarred code within NetBeans.
    Executing code works fine within NB if I don't use packages. However, when I use packages, I get NoClassDefFoundErrors for dependencies. That is, my main class gets found, but its dependencies do not.
    Can someone please show me how it's done in NB 3.5.1? Also, should I create an Ant task to execute my code from within the IDE?
    D:\
    ----+com
    --------+myco
    ------------+myapp
    ----------------+myMain.java              /*this does get found*/
    ------------+mydep
    ----------------+myDependency.java        /*this does not get found*/
    I've searched the NB website, but there is just too much stuff to wade through. And of course, I've searched the forums here too. I'd appreciate any help! Thanks!
    PGynt

    Hi,
    Thanks for replying!
    the d:\ folder needs to be mounted as a filesystem.Please see expanded structure below.
    All dependency classes need to be compiled
    (add them to the project and build all).I'm using Ant to compile within NetBeans. It creates a build directory which mirrors the source code directory structure. Package names are same as directory structure. It all runs fine within a jar, but only outside of NB. Below is an expanded version of my structure. Maybe it will make things clearer.
    If you like ANT, maybe you should
    upgrade to netbeans 4.1 because it uses ANT as it's
    build engine.Sounds good, but it's not in our budget for now. Changes always take so much time.
    D:\
    ----+application/*this directory is mounted and added to project*/
    --------+src  /*this directory is mounted and added to project*/
    ------------+com
    ----------------+myco
    --------------------+myapp
    ------------------------+myMain.java /*this does get found*/
    --------------------+mydep
    ------------------------+myDependency.java /*this does not get found*/
    --------+build
    ------------+com
    ----------------+myco
    --------------------+myapp
    ------------------------+myMain.class  /*this does get found*/
    --------------------+mydep
    ------------------------+myDependency.class /*this does not get found*/
    Is it necessary to add classes to a project for executing a program? Or is mounting the relevant directories enough?
    Again, I'm used to using Ant directly, so I'm sorry if that sounds like a dumb question.
    PG

  • Execute code when IE Browser closes

    Help!  I'm trying to find a way to run a SQL statement when a user closes a IE window (X's out).  I've found information on the onBeforeUnload event but I've been unsucessful at getting it to run.
    Does anyone have another suggestion?  Is it even possible to execute code upon closing a window?
    Thanks!!!

    Thanks ilssac.  I figured this was the case based on my research but I thought I'd present it to the Forum just to be sure.
    Basically, I've been asked to limit the number of logins to a small Coldfusion application.  I've coded it so that I increment a counter in the DB and I decrement it when the user logs out properly (by clicking a logout link).  But if the user just closes the window then the decrement doesn't happen and this created problems.
    If you have any suggestions I would really appreciate it.
    Thanks for your time!!!!

  • Execute Code on closing frame

    Dear friends,
    I would like to know how to execute code on closing the frame.

              JFrame frame = new JFrame();
              WindowListener l = new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                             // Do here what you want ...                    }
              frame.addWindowListener(l);

  • Execute code from a text file ...

    Hello ,  Would like to know whether it is possible to have my ABAP code in a text file in desktop and then execute the code by reading it into an ITAB in another ABAP program .
    Note : Pl. dont suggest how to upload and create a new program . I dont want to create a new program after uploading into ITAB using INSERT or function modules . I want to execute the code as part of the uploading program only . So that once the execution is complete the uploaded code will not be available in the SAP system.
    Thanks in advance ,
    Jee.R

    >
    jeeva R wrote:
    > Note : Pl. dont suggest how to upload and create a new program . I dont want to create a new program after uploading into ITAB using INSERT or function modules . I want to execute the code as part of the uploading program only . So that once the execution is complete the uploaded code will not be available in the SAP system.
    Oh dear.  The only solution to your requirement is, sadly, to upload and create a new program, and then one further step.  There is no other way.  So it looks like you'll have to do without.
    matt

  • Can a swf file begin executing code before loading completely?

    I have a swf file with a preloader on the stage at authoring
    time. The preloader centers itself by retrieving the stage
    dimensions and calculating the coordinates it needs.
    This works everytime in Flash preview, but once I put it
    online it only works sometimes, mostly after I refresh the page.
    The stage width and height it seems, are considered = 0 when this
    happens and so my preloader doesn't position itself correctly.
    The only reason I can determine for this error is that when
    the code begins to execute the swf is not fully loaded, and thus it
    gets wrong stage dimensions. I have exported the swf file to have
    100% width and heigth, don't know if there are known issues with
    this mode of publishing.
    Any help on this matter is appreciated, thanks in
    advance.

    Hi Tim,
    This idea offers some interesting possibilities. (Thank you.)
    I'll have play with it to see if I can make it meet our needs.
    I'm worried that the caption would be forced inside of the
    perimeter of the movie, instead of outside next to the playback
    controls.
    If there was a way to get the timer to line up with the
    playback controls outside of the Captivate 4 movie, that would be
    ideal. Here is a
    Snapshot
    of what we are trying to re-create in CP4.
    - Tom -

  • How to execute code from a text file?

    Hello all!
    How to execute some code lines from a text file? For example my file is:
    String varname = "somecontents";
    JFrame frame = new JFrame();
    frame.setVisible(true);How can I get contents of this file and parse them if I want get new JFrame and access to the variable varname?

    I mean the PHP would generate a readable Java source,
    for example some variables with some data, and I just
    dont know what to do with file if I want generate the
    xls file from my saved data, could You help? :)Some variables, some data, PHP, Java, XLS file??? Al rather vague.
    You need to explain in more detail what it is you're trying to do if you want an answer to your question!

  • I only see "PHP" icons in Design View, not the executed code

    I have setup a new database installation and tested it - no problem.  I can open my webpage in Firefox, and the php code executes properly.  When I imported this site into Dreamweaver, I am unable to see the results of any executed PHP code, just "PHP" icons.
    Is it possible to view the results of the executed PHP code in Dreamweaver.   I'm not talking about complicated PHP code, just a bunch of 'echo' statements really.
    Thanks from a DreamWeaver newbie.

    I have moved your thread to the appropriate forum, Dreamweaver Application Development, which is where PHP-related issues should be discussed.
    In answer to your question, PHP is a server-side language that needs to be parsed (executed) through a web server capable of handling PHP code. In order to see the output of the PHP code, you need to set up a testing server. Instructions on how to do so can be found in this article in the Dreamweaver Developer Centre. Once you have set up a testing server, you can see the output of the PHP code in Design view by activating Live View (in Dreamweaver CS4) or Live Data view in earlier versions of Dreamweaver.

  • Java Server execute code on exit

    Hi,
    I want to make a simple server in java and i want it to execute some code (flush files, etc..) when i tell the server to stop.
    I want to be able to do this like a service on linux (calling some script and giving a param stop).
    Something like responding to a given signal whould be nice.
    Did i make myself clear?
    Thanks,
    Ricardo Lopes.

    Or only accept "STOP" from localhost?Yep i thought about that.
    And it came to my mind that an attacker could use ip soffing ???
    I think that my firewall should block that traffic, i believe that there is a rule that says to reject all traffic from localhost than come from an interface different that lo but i'm not sure.
    The commons daemon seems to be off-line i will take a look later.

Maybe you are looking for