Results 1 to 20 of 25
- 07-14-2008, 08:52 AM #1
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
[SOLVED] On Exit JoptionPane problem
Hi all
I have a problem in OnExit JOptionPane.I want to set the option when user click on Cancel option then Farme not close. My current code is this..
Java Code:int exit = JOptionPane.showConfirmDialog(null, "Are you sure?"); if (exit == JOptionPane.YES_OPTION) { try { Runtime.getRuntime().exec("cmd.exe /c start www.yahoo.com"); } catch (Exception exception) { System.out.println("Exception caught : " + exception.getMessage()); } System.exit(0); } if (exit == JOptionPane.NO_OPTION) { System.exit(0); } if (exit == JOptionPane.CANCEL_OPTION) { System.exit(0); } // System.exit(0);
- 07-14-2008, 09:06 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
On the cancel option you exit the application. You are not involving with any frame there.
- 07-14-2008, 09:22 AM #3
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 09:23 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
If you want to close/dispose a frame you need a reference to that frame. Is this done on the same frame you are talking about?
- 07-14-2008, 09:35 AM #5
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
No sir i don,t want to close or dispose frame on Cancel option.Frame is close on Yes option.I want when user click on Cancel button then work still same.But in this code when i use cancel option without
Java Code:System.ext(0)
So how i can do that.I have no idea bout that..
Plz help me
- 07-14-2008, 09:53 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
In all three options(Yes, No, Cancel) you have done the same thing at the end. Exit the application.
Java Code:System.exit(0);
As I said, what you have to do is, use a reference to the frame. You can use dipose() or exit() methods.
- 07-14-2008, 09:58 AM #7
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
Sir as you say to use Frame reference.I use these reference and my updated code is here..But output is same..
Java Code:int exit = JOptionPane.showConfirmDialog(mainFrame, "Are you sure?"); if (exit == JOptionPane.YES_OPTION) { try { Runtime.getRuntime().exec("cmd.exe /c start www.yahoo.com"); } catch (Exception exception) { System.out.println("Exception caught : " + exception.getMessage()); } System.exit(0); } else { }
- 07-14-2008, 10:04 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
I don't know what you are talking about. Can show me only the reference to the frame here. Highlight the reference on the above code to see me.
I'm confusing that you know about the object reference in Java.
- 07-14-2008, 10:08 AM #9
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 10:53 AM #10
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 11:22 AM #11
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 11:27 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Simply call a function using that reference in the main frame class. On that method dispose/exit the frame.
- 07-14-2008, 12:17 PM #13
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 12:23 PM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
In your code, even on the Yes option it can't work. See the code in Yes and Cancel options. There is no different. So what are you talking about, in any option you don't have handle any event on the frame.
- 07-14-2008, 12:28 PM #15
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 12:36 PM #16
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
Sir i create a even handel in frame class.Now i call it in main class..
Java Code:protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { int exit = JOptionPane.showConfirmDialog(this, "Are you sure?"); if (exit == JOptionPane.YES_OPTION) { System.exit(0); } } else { // If you do not want listeners processing the WINDOW_CLOSING // events, you could this next call in an else block for the: // if (e.getID() ...) // statement. That way, only the other types of Window events // (iconification, activation, etc.) would be sent out. super.processWindowEvent(e); } }
- 07-14-2008, 01:02 PM #17
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 01:31 PM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Seems you copied this code somewhere. If not you should know what happened here. That code is related to the closing event of the frame. Not the JOptionPane stuff you are talking about earlier.
- 07-14-2008, 01:53 PM #19
Senior Member
- Join Date
- Mar 2008
- Posts
- 447
- Rep Power
- 13
- 07-14-2008, 03:39 PM #20
Hi
according to question you want to do the following:
1) when the user click on yes, An Application will open the browser say Yahoo! and exit
2) on clicking no button an Application will exit without opening the browser
and
3) on clicking cancel button that dialog box should be closed.
Please tell me whether i am right or wrong with your question..Thanks & Regards
Subroto Bhattacharjee:)
Similar Threads
-
JVM terminated Exit code=1
By oregon in forum EclipseReplies: 3Last Post: 09-29-2008, 10:49 PM -
system.exit(..)
By ramakanta.majhi in forum New To JavaReplies: 2Last Post: 06-14-2008, 02:28 AM -
Problem with JOptionPane.showInputDialog()
By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 06:33 AM -
help with System.exit (1) function call
By katie in forum Advanced JavaReplies: 2Last Post: 08-06-2007, 09:03 PM -
How to exit the program..
By coco in forum New To JavaReplies: 1Last Post: 08-01-2007, 06:56 PM
Bookmarks