Results 1 to 20 of 23
- 09-04-2009, 05:27 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
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:
Do I need to do something more to tie the windows generated X button in the FRAME to the exit method?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: }Last edited by TimHuey; 09-04-2009 at 05:30 AM.
-
A Google search brought me this jem from forums.sun.com:
Swing - Re: Closing a Swing App Through Menu ( File -> Exit )
Lots of great information contained here. Much luck!
- 09-04-2009, 06:22 AM #3
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
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.
- 09-04-2009, 08:27 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 09-04-2009, 12:41 PM #5
Member
- Join Date
- Sep 2009
- Location
- BlackVelds
- Posts
- 3
- Rep Power
- 0
Have you tried>>> name_of_frame.setDefaultCloseOperation(JFrame.EXIT _ON_CLOSE);
- 09-04-2009, 12:45 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 09-04-2009, 07:07 PM #7
Member
- Join Date
- Sep 2009
- Location
- BlackVelds
- Posts
- 3
- Rep Power
- 0
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);
}
} //
- 09-05-2009, 05:03 PM #8
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
- 09-05-2009, 05:20 PM #9
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
I'm wondering if it's the launching program that is staying alive. Here is the code:
I tried altering it slightly with the windowlistener: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); } }
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); } }
- 09-05-2009, 05:43 PM #10
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 09-05-2009, 05:47 PM #11
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
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.
- 09-05-2009, 05:49 PM #12
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 09-06-2009, 12:21 AM #13
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
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.
- 09-06-2009, 02:26 AM #14
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
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.
- 09-06-2009, 02:39 AM #15
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
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.
-
I like your plan. Please keep us posted, especially if you find a solution!
- 09-06-2009, 03:45 AM #17
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
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.
-
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.
- 09-06-2009, 03:56 AM #19
Member
- Join Date
- Aug 2009
- Posts
- 50
- Rep Power
- 0
IM DA MAN! IM DA MAN IM DA MAN!!!
WHOOOHOOOO! I fixed it i fixed it I fixed it!!!!!!!!!!!!!!
-
You da man! (now what's the solution?) :)
Similar Threads
-
Halt applet processes.
By barusk in forum Java AppletsReplies: 1Last Post: 04-06-2009, 05:11 PM -
killing a java process
By paritoshcg in forum Advanced JavaReplies: 3Last Post: 12-01-2008, 08:16 AM -
Killing an Ill-behaved Thread
By John6715 in forum Threads and SynchronizationReplies: 6Last Post: 10-03-2008, 08:35 AM -
Thread killing
By denis in forum Threads and SynchronizationReplies: 13Last Post: 09-25-2008, 09:28 PM -
netbeans processes don´t die
By karlen in forum NetBeansReplies: 0Last Post: 06-11-2007, 09:55 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks