Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default GUI not killing processes when X is used to exit

    I used netbeans to help develop a GUI application. Everything exits great when the users uses the FILE - EXIT menu option. However, in windows there is an X in the upper righthand corner of the frame that can be used to exit an application. When the user uses that exit method the java process doesn't get killed. The GUI disappears but the java.exe process in the task manager stays on and the cleanup of some files that were created doesn't take place.

    Here is my code for the file - exit menu option:

    Java Code:
    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
    //    seq1Dialog.dispose();
    //    seq2Dialog.dispose();
        File f1 = new File(System.getProperty("user.home")+System.getProperty("file.separator")+"lines.txt");
        File f2 = new File(System.getProperty("user.home")+System.getProperty("file.separator")+"pairings.txt");
        File f3 = new File(System.getProperty("user.home")+System.getProperty("file.separator")+"Eqps.txt");
        
        boolean successfullinesdelete = f1.delete();
        boolean successfulpairingsdelete = f2.delete();
        boolean successfuleqpdelete = f3.delete();
    
        if (!(successfuleqpdelete && successfullinesdelete && successfulpairingsdelete)){
          System.out.println("Deletion failed. Check files");
          System.exit(0);
        }else{
          System.out.println("All Bidit Files deleted.");
        }
        System.exit(0);// TODO add your handling code here:
    }
    Do I need to do something more to tie the windows generated X button in the FRAME to the exit method?
    Last edited by TimHuey; 09-04-2009 at 05:30 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    I have tried setting that behavior they mention exit_on_close before. It didn't seem to help. I will keep trying to figure this out. Thanks for digging that up.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by TimHuey View Post
    I have tried setting that behavior they mention exit_on_close before. It didn't seem to help. I will keep trying to figure this out. Thanks for digging that up.
    Why don't you post what you tried then.

  5. #5
    thirdSon is offline Member
    Join Date
    Sep 2009
    Location
    BlackVelds
    Posts
    3
    Rep Power
    0

    Default

    Have you tried>>> name_of_frame.setDefaultCloseOperation(JFrame.EXIT _ON_CLOSE);

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by thirdSon View Post
    Have you tried>>> name_of_frame.setDefaultCloseOperation(JFrame.EXIT _ON_CLOSE);
    I don't think they want to do that.
    They should rather add a windowListener and perform their clean up in the windowClosing event.
    Last edited by r035198x; 09-04-2009 at 07:08 PM.

  7. #7
    thirdSon is offline Member
    Join Date
    Sep 2009
    Location
    BlackVelds
    Posts
    3
    Rep Power
    0

    Default

    then try this>>>put this in the void main ()
    name_of_frame.addWindowListener(new myWindowListener()); // put in the public static void main

    static class myWindowListener extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    } //

  8. #8
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Why don't you post what you tried then.
    Sorry, I should do that, here ya go. You guys are great for looking at this:

    Java Code:
    BiditApp.getApplication().getMainFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  9. #9
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    I'm wondering if it's the launching program that is staying alive. Here is the code:

    Java Code:
    package bidit;
    
    import org.jdesktop.application.Application;
    import org.jdesktop.application.SingleFrameApplication;
    
    /**
     * The main class of the application.
     */
    public class BiditApp extends SingleFrameApplication {
    
        /**
         * At startup create and show the main frame of the application.
         */
        @Override protected void startup() {
            show(new BiditView(this));
        }
    
        /**
         * This method is to initialize the specified window by injecting resources.
         * Windows shown in our application come fully initialized from the GUI
         * builder, so this additional configuration is not needed.
         */
        @Override protected void configureWindow(java.awt.Window root) {
        }
    
        /**
         * A convenient static getter for the application instance.
         * @return the instance of GuiPiecesApp
         */
        public static BiditApp getApplication() {
            return Application.getInstance(BiditApp.class);
        }
    
        /**
         * Main method launching the application.
         */
        public static void main(String[] args) {
            launch(BiditApp.class, args);
        }
    }
    I tried altering it slightly with the windowlistener:

    Java Code:
    package bidit;
    
    import org.jdesktop.application.Application;
    import org.jdesktop.application.Application.ExitListener;
    import org.jdesktop.application.SingleFrameApplication;
    
    /**
     * The main class of the application.
     */
    public class BiditApp extends SingleFrameApplication {
    
        /**
         * At startup create and show the main frame of the application.
         */
        @Override protected void startup() {
            show(new BiditView(this));
        }
        
    
    [B]    @Override
        public void addExitListener(ExitListener myWindowListener) {
            super.addExitListener(myWindowListener);
        }
        /**[/B]
         * This method is to initialize the specified window by injecting resources.
         * Windows shown in our application come fully initialized from the GUI
         * builder, so this additional configuration is not needed.
         */
        @Override protected void configureWindow(java.awt.Window root) {
        }
    
        /**
         * A convenient static getter for the application instance.
         * @return the instance of GuiPiecesApp
         */
        public static BiditApp getApplication() {
            return Application.getInstance(BiditApp.class);
        }
    
        /**
         * Main method launching the application.
         */
        public static void main(String[] args) {
            launch(BiditApp.class, args);
        }
    }

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    As I've already been saying in the last posts, don't set the default close operation if you want to do some clean up code. Add a WindowListener and call that clean up code you have in the exitMenuItemActionPerformed method in that action.

  11. #11
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    As I've already been saying in the last posts, don't set the default close operation if you want to do some clean up code. Add a WindowListener and call that clean up code you have in the exitMenuItemActionPerformed method in that action.
    Yep, I did that. I commented it out to take it out of the equation. In addition, it never gets used anyway, I don't use the FILE then EXIT command from the application. When I do that, it exits correctly. It's only the windows program closing action (using the red X in the upper right corner of the frame) that isn't working correctly.

    Maybe I should work on finding a way to take that option away from the user till I get it to clean up correctly. Force them to use the program exit instead.
    Last edited by TimHuey; 09-05-2009 at 05:51 PM.

  12. #12
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Wait, you are using Netbeans? Well then how do you know whether the java.exe process you are seeing in task manager is not Netbeans'?
    I wouldn't base everything on what the windows task manager says.

  13. #13
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    I thought about that as well. So I shut netbeans down and run it from the command line java -jar bidit.jar

    Still stays in task manger as java.exe*32 after shut down. or something close to that. Im going to try a few other netbeans developed apps and see if they exhibit the same behavior.
    Last edited by TimHuey; 09-06-2009 at 12:37 AM.

  14. #14
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    If they don't exhibit the same behavior and shut down correctly. I will begin to add in bits and pieces of my code until I find the part that causes the program to exhibit the same behavior....which I probably won't understand why, but at least at that point I will have an intelligent question to ask. Something other than ..."My program does this...fix it." Kinda makes you feel like a leech.

  15. #15
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    WOW! That didn't take long at all!! I just added my personal variables I declared. And with just my declaration of those variables the new GUI is exhibiting the strange behavior. I think I may be able to fix this on my own.

    I will attempt to find the one...but I have a sneaky suspicion its:

    JFrame mainFrame = BadBehaviorApp.getApplication().getMainFrame();

    I'm probably not supposed to do that for some reason. I will let you guys know when I hit a roadblock with this attack method.

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  17. #17
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    You have 3813 post...I think you probably already know the answer. But thanks for letting me try to figure it out for myself. I will let you know when I have no hair left to pull out.

  18. #18
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Please don't mistake post count with knowledge. If I knew the answer, I'd post it, but as I don't, I won't.
    Last edited by Fubarable; 09-06-2009 at 04:02 AM.

  19. #19
    TimHuey is offline Member
    Join Date
    Aug 2009
    Posts
    50
    Rep Power
    0

    Default

    IM DA MAN! IM DA MAN IM DA MAN!!!


    WHOOOHOOOO! I fixed it i fixed it I fixed it!!!!!!!!!!!!!!

  20. #20
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Page 1 of 2 12 LastLast

Similar Threads

  1. Halt applet processes.
    By barusk in forum Java Applets
    Replies: 1
    Last Post: 04-06-2009, 05:11 PM
  2. killing a java process
    By paritoshcg in forum Advanced Java
    Replies: 3
    Last Post: 12-01-2008, 08:16 AM
  3. Killing an Ill-behaved Thread
    By John6715 in forum Threads and Synchronization
    Replies: 6
    Last Post: 10-03-2008, 08:35 AM
  4. Thread killing
    By denis in forum Threads and Synchronization
    Replies: 13
    Last Post: 09-25-2008, 09:28 PM
  5. netbeans processes don´t die
    By karlen in forum NetBeans
    Replies: 0
    Last Post: 06-11-2007, 09:55 PM

Posting Permissions

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