Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default [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);

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    On the cancel option you exit the application. You are not involving with any frame there.
    Then How can i do that.Any idea about that..

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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?

  5. #5
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    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?
    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)
    then code is hange...

    So how i can do that.I have no idea bout that..

    Plz help me

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    In all three options(Yes, No, Cancel) you have done the same thing at the end. Exit the application.

    Java Code:
    System.exit(0);
    You say that on yes option frame is close. Where's the code? I can't see any related code there. Only thing is you execute the browser with a specified URL.

    As I said, what you have to do is, use a reference to the frame. You can use dipose() or exit() methods.

  7. #7
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    In all three options(Yes, No, Cancel) you have done the same thing at the end. Exit the application.

    Java Code:
    System.exit(0);
    You say that on yes option frame is close. Where's the code? I can't see any related code there. Only thing is you execute the browser with a specified URL.

    As I said, what you have to do is, use a reference to the frame. You can use dipose() or exit() methods.
    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
    		    {
    		    	
    		    }
    Plz help me

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  9. #9
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    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.
    ok Sir

    Java Code:
    mainFrame
    it is a reference of Frame.

  10. #10
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    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.
    Sir can you tell me where i am wrong..

  11. #11
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    In all three options(Yes, No, Cancel) you have done the same thing at the end. Exit the application.

    Java Code:
    System.exit(0);
    You say that on yes option frame is close. Where's the code? I can't see any related code there. Only thing is you execute the browser with a specified URL.

    As I said, what you have to do is, use a reference to the frame. You can use dipose() or exit() methods.
    Sir give me tips to solve it..

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Simply call a function using that reference in the main frame class. On that method dispose/exit the frame.

  13. #13
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    Simply call a function using that reference in the main frame class. On that method dispose/exit the frame.
    Sir i want to know some concept.Why it is not working for Cancel option and other hand it is working good for yes option.What's a resion behiend it.Just i want to know hide concept..

    Plz help me

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  15. #15
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    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.
    So first i add event handel then i call it is main Class..

  16. #16
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    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.
    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);
            }
        }
    how i call it sir..plz help me

  17. #17
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    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.
    can you give me some example rellated to this sir..

    Plz help me

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  19. #19
    Mir
    Mir is offline Senior Member
    Join Date
    Mar 2008
    Posts
    447
    Rep Power
    7

    Default

    Quote Originally Posted by Eranga View Post
    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.
    yes you are right..i copied these code.But plz give me right way..

  20. #20
    Join Date
    May 2008
    Location
    India,Kolkatta
    Posts
    50
    Rep Power
    0

    Default

    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:)

Page 1 of 2 12 LastLast

Similar Threads

  1. JVM terminated Exit code=1
    By oregon in forum Eclipse
    Replies: 3
    Last Post: 09-29-2008, 09:49 PM
  2. system.exit(..)
    By ramakanta.majhi in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 01:28 AM
  3. Problem with JOptionPane.showInputDialog()
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:33 AM
  4. help with System.exit (1) function call
    By katie in forum Advanced Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 PM
  5. How to exit the program..
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 05:56 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
  •