How to use the cancel button in showInputDialog

um how would i go with overriding the cancel button's deafult function in JOptionPane.showInputDialog?
in my code:
package alphaOne;
* this program takes in a number and gets the factorial of that number
import javax.swing.*;
public class Factorial {
     public Factorial() {
           * variables intilization, input is where the option pane puts the data
           * number is teh actucal number entered parsed from string result is
           * where the resutl is stored flag1 is the indicator if the user had
           * entered an integer
          String input;
          int flag1 = 0;
          int number = 0;
          long result = 0;
           * this while loop runs continously unless an integer is entered
          while (flag1 != 1)
               try {
                    input = JOptionPane
                              .showInputDialog("Enter the number to be factored, Integer only: ");
                    number = Integer.parseInt(input);
                    flag1 = 1;
               } catch (NumberFormatException ea) {
                    JOptionPane.showMessageDialog(null,
                              "The input was not a integer!", "Warning",
                              JOptionPane.ERROR_MESSAGE);
          result = number;
          for (int x = 1; x < number; x++) {
               result = result * (x);
          JOptionPane.showMessageDialog(null, "The result is: " + result,
                    "Result", JOptionPane.CLOSED_OPTION);
          try {
               System.exit(0);
          } catch (SecurityException ea) {
               System.out.print("ARRRRR its dead!");
     public static void main(String[] args) {
          Factorial One = new Factorial();
}the cancel button does not break the while loop

what is the value of null compared to when you compare it, and do we use the String.equals() or the String == null to compare? as seen in here i tried with input.equals(null) as a comparison but it deos not exit when i press cancel
package alphaOne;
* this program takes in a number and gets the factorial of that number
import javax.swing.*;
public class Factorial {
     public Factorial() {
           * variables intilization, input is where the option pane puts the data
           * number is teh actucal number entered parsed from string result is
           * where the resutl is stored flag1 is the indicator if the user had
           * entered an integer
          String input;
          boolean flag1 = false;
          int number = 0;
          long result = 0;
           * this while loop runs continously unless an integer is entered
          while (flag1 != true){
               try {
                    input = JOptionPane
                              .showInputDialog("Enter the number to be factored, Integer only: ");
                    number = Integer.parseInt(input);
                    System.out.println(input);
                    flag1 = true;
                    if (input.equals(null))
                         try {
                              System.exit(0);
                         } catch (SecurityException ea) {
                              System.out.print("ARRRRR its dead!");
               } catch (NumberFormatException ea) {
                    JOptionPane.showMessageDialog(null,
                              "The input was not a integer!", "Warning",
                              JOptionPane.ERROR_MESSAGE);
          result = number;
          for (int x = 1; x < number; x++) {
               result = result * (x);
          JOptionPane.showMessageDialog(null, "The result is: " + result,
                    "Result", JOptionPane.INFORMATION_MESSAGE);
          try {
               System.exit(0);
          } catch (SecurityException ea) {
               System.out.print("ARRRRR its dead!");
     public static void main(String[] args) {
          Factorial One = new Factorial();
}i have also tried to ue input == null, input == "", input.equals(""), input.equals(" ")
Message was edited by:
TheHolyLancer
i edited the part so it is bold
Message was edited by:
TheHolyLancer

Similar Messages

  • How to disable the cancel button in InputDialogBox?

    Can someone please tell me how to disable the cancel button in an input dialog box?
    thanks,

    Cross posted: [http://www.coderanch.com/t/487888/Swing-AWT-SWT-JFace/java/disable-cancel-button-input-dialog]

  • How to disable the cancel button in the ProgressMonitor

    hi,
    I need to know, is there any way to disable/remove the (cancel)button in the ProgressMonitor?
    One more problem is,
    Once i click the cancel button, isCanceled() return true, how to make it false again so that the process continue....
    It is very urgently.....
    please help me out.
    Thanks in advance.
    Regards,
    Deepa Raghuraman

    I don't think that's a good solution, because Cancel button itself is not disabled, so user is tempted to click it and nothing happens.
    A better but dangerous solution is this:
    progressMonitor = new ProgressMonitor(ProgressMonitorDemo.this,
                                         "Running a Long Task",
                                         "", 0, 100);
    progressMonitor.setMillisToDecideToPopup(0);
    progressMonitor.setMillisToPopup(0);
    progressMonitor.setProgress(0);
    JDialog dialog = (JDialog)progressMonitor.getAccessibleContext().getAccessibleParent();
    JOptionPane pane = (JOptionPane)dialog.getContentPane().getComponent(0);
    pane.setOptions(new Object[]{});Refer to the same question here [http://stackoverflow.com/questions/512151/how-do-i-disable-the-cancel-button-when-using-javax-swing-progressmonitor] .

  • How to use a cancel button........

    hello everyone,
                  i have a selection screen, from where i am calling a selection-screen as a pop-up screen. the fields i am checking on the pop-up screen will get append on the previous screen. now the problem i am facing with the cancel button.
        if i am pressing the cancel button still the checked fields are getting appended.
    i want to exit from the screen and want to keep the previous screen as it is. it is a simple report program.
    please help me out.
    thanks i advance.

    I am using set screen 0. and leave screen.
    but still the problem persists.
    let me tell you in detail.
    i am going to pop-up screen to get the fields appended on my previous screen.
    if i check some checkboxes on it and click ok then according to those checked fields the corresponding select-options should come on previous screen. 
    because i have added set screen 0. to 'OK'.
    now what i am facing is if i check some checkboxes on the pop-up and say 'CANCEL' still the program is appending the those checkboxes and appending them on the previous screen.
    what i am expecting is, it should exit the pop-up screen and should maintain the previous screen as it is.
    thanks

  • Apple Keybord ADB (Anyone knows how to use the power button?)

    Hi, I just found my uncle's old Mac SE and I was wondering if anyone knows how to set the power button on the keyboard (Apple Keyboard) model number M0116C? I want this key to work, because it is actualy not working.
    Tanks!

    Hi, I just found my uncle's old Mac SE and I was
    wondering if anyone knows how to set the power button
    on the keyboard (Apple Keyboard) model number M0116C?
    I want this key to work, because it is actualy not
    working.
    You don't make any settings for the power switch; either the Mac can use it or it can't. The Mac SE has a rocker power switch on the back of the CPU. The keyboard can't change the state of the power supply. Later Macs could, but not the SE.

  • How to use the cancel indicator in ME28

    Hi frnds..
      Where to configure cancel indicator in ME28 transaction, What is the use of that.

    When you will try to cancel the release strategy (After release), this option is used in ME28.
    But before that, you have to select the tick option in ME28.
    Then you can see the PO which release status says as "Release already effected"
    Then you can cancel the release by using the Cancel Release.
    Regards
    Dev

  • How to handle the "cancel" button and "close" icon of a popup ?

    Hi,
    I have a popup with "cancel button" and "close icon"(on the top right corner of the popup), I want the same operations to be performed on clicking of any of these two components.
    Is there a way to handle such situation ?
    I read about 2 cases to look into this but they didn't work too well for me.
    1. I read about the "popcancellistener" but that listener is called whenever the popup closes, so suppose I have an "ok button" on the popup to create a record, after the record is created, the popup closes and goes into the "popcancellistener", now the question is "how do we know if it came there because of the 'ok button' or 'some other event'".
    2. I even checked the "DialogListener", now I'm able to distinguish between the 'OK' and 'CANCEL' button in the dialoglistener using the "Dialog.Outcome.ok/cancel", but when a user clicks on the close icon, we do not enter the "DialogListener" at all, so in this case "how do we handle the close icon click event"
    Do let me know if you need any more information from my side.
    Thanks for the help in advance.

    The following mechanism responds to any of the following events: <Esc> key, Close icon ('x'), Cancel button
    JavaScript part:
    function popupClosedListener(event){
                  var source = event.getSource();
                  var popupId = source.getClientId();
                  var params = {};
                  params['popupId'] = popupId;
                  var type = "serverPopupClosed";
                  var immediate = true;
                  AdfCustomEvent.queue(source, type, params, immediate);
    }JSF part:
             <af:popup ....>
                  <af:clientListener method="popupClosedListener"
                                           type="popupClosed"/>
                  <af:serverListener type="serverPopupClosed"
                                          method="#{myBean.serverPopupClosedMetod}"/>
            </af:popup>Finally, Java part:
    public void serverPopupClosedMetod(ClientEvent event){
    }

  • How to use the submit button without an email address

    We are changing the way one of our forms is used.  Previously the "submit by email" button opened up an email with a specific TO: address.  Now we like to have the user put in the address but still have the form attached to the email when it is opened. 
    Has anyone done this or does anyone have an idea how we can accomplish this?

    Place a HTTP submit button in your form and update the User Entered email using the below script.
    YourHTTPSubmitButton.event__click.submit.target = "mailto:" + txtEmailField.rawValue

  • How to enable the "Cancel button" so you can stop a report while loading ...

    I have seen that some reports have a Cancel button located just below "the loading ..".
    How can I enable that button in MS Reporting service 2005?

    The following mechanism responds to any of the following events: <Esc> key, Close icon ('x'), Cancel button
    JavaScript part:
    function popupClosedListener(event){
                  var source = event.getSource();
                  var popupId = source.getClientId();
                  var params = {};
                  params['popupId'] = popupId;
                  var type = "serverPopupClosed";
                  var immediate = true;
                  AdfCustomEvent.queue(source, type, params, immediate);
    }JSF part:
             <af:popup ....>
                  <af:clientListener method="popupClosedListener"
                                           type="popupClosed"/>
                  <af:serverListener type="serverPopupClosed"
                                          method="#{myBean.serverPopupClosedMetod}"/>
            </af:popup>Finally, Java part:
    public void serverPopupClosedMetod(ClientEvent event){
    }

  • Do u know how to use the edit button (abc or penci...

    Heres how... in the inbox for example; u wanna delete multiple sms, simply hold the edit button, scroll down, and then, press c to delete the marked sms. The edit button can also b used to copy and past text in sms, simply hold it and scroll across, choose copy. pretty good for placing song names in ngages
    Rahul$

    Hi alata
    Select the "pencil" button, scroll down to Predictive Text > "Matches" and then the list becomes available.
    Star key(*)bottom left on pad will change words. Keep pressing until your happy with the word or you will be asked to spell it.
    Happy to have helped forum in a small way with a Support Ratio = 37.0

  • How to use the 3 button mouse to swipe from one window to another window

    when I use the trackpad in the macbook pro 2010 with 3 fingers, I can easily swipe left or right to another window that I setup one for my home and one for my office work, but I also use a external mouse, keyboard and big display to use the MBP with the lib close, this case how can do this with mouse itself under osx mavericks 10.9.1
    thanks.

    Hi,
            Any data sharing accross views can be achiveved by defining CONTEXT data in COMPONENT CONTROLLER and mapping it to the CONTEXT of all the views. Follow the below steps.
    1. Define a CONTEXT NODE in component controller
    2. Define same CONTEXT NODE in all the views where this has to be accessed & changed.
    3. Go to CONTEXT NODE of each view, right click on the node and choose DEFINE MAPPING.
    This is how you map CONTEXT NODE and same can be accessed/changed from any VIEW or even from COMPONENT CONTROLLER. Any change happens at one VIEW will be automatically available in others.
    Check the below link for more info regarding same.
    [http://help.sap.com/saphelp_nw04s/helpdata/EN/48/444941db42f423e10000000a155106/content.htm]
    Regards,
    Manne.

  • How to use the same button to control run or stop of the program?

    I want to run a program when I press Boolen2, I use switch when press. So when I press it, it will turn "on" stature. There is a loop in the program. I want to stop it, when press the button again, that is when make the button from "on" statue to "off" stature.
    But I don't know why it doesn't work in my vi. And is there other good way?
    Thank you.
    Attachments:
    question2.vi ‏124 KB

    Hi,
    Thank you very much.Please download this file and save it under the same path,and change its extern name to dll.
    I have tried follow your vi. But this method doesn't work properly in my vi. I don't know why.
    Maybe it is because there is a highspeed data acquisition working in the loop. And I have tried to wait 100ms every loop.But it doesn't work.
    Thank you for your help.
    Hugo Liang. 
    Attachments:
    MP421.txt ‏237 KB

  • In plain English can someone tell me how to use the unsubscribe button or get it to show up in the "unsubscribe from mailing list" ad-on?

    There's nothing to detail it doesn't work.

    In plain English.
    If the unsubscribe header the add-on uses is present it shows up in the mail header along with the from Subject to etc. With or Without the add-on. So if there is no entry in the header, then the mail sender does not support that style of unsubscribing. In the United States unsubscribing from a mailing list is troublesome as legislators are either are unable or unwilling to understand the problem. Given the amounts of money involved I will go with the latter.
    Any difficulties you have with the actual add-on need to be dealt with by the add-on author The download page list a support link. https://addons.mozilla.org/en-US/thunderbird/addon/unsubscribe-from-mailing-list/?src=search

  • Credit Limit - How to Use the Foward button in VKM4

    Hi all,
    I have an enquiry here. In VKM4, we can see that there is a 'Foward' icon where we will be able to foward the respective sales order to an authorize person for approval. After I Foward and Save it, system only prompts me saying the SO has been forwarded.
    1. I would like to know where can I check who is it fowarded to and what happened after I clicked on Save
    2. Do I have to configure some email or notifications thing as I would like a notification email to be sent to the approver aft I have forwared the SO
    3. Appreciate if someone could share any documents, information or knowledge on this as there is not much of this info on the web.
    Thank you in advance!
    Regards,
    Yvonne

    Hi all,
    I have an enquiry here. In VKM4, we can see that there is a 'Foward' icon where we will be able to foward the respective sales order to an authorize person for approval. After I Foward and Save it, system only prompts me saying the SO has been forwarded.
    1. I would like to know where can I check who is it fowarded to and what happened after I clicked on Save
    2. Do I have to configure some email or notifications thing as I would like a notification email to be sent to the approver aft I have forwared the SO
    3. Appreciate if someone could share any documents, information or knowledge on this as there is not much of this info on the web.
    Thank you in advance!
    Regards,
    Yvonne

  • I entered time machine and wish to exit but the cancel button has no effect and neither does command quit.  I have no access to the Apple toolbar to use force quit.  How do I get out of this thing?????

    I opened the backup window of my time machine.  I now wish to exit.  The cancel button and Command quit have no effect.  Turning off the IMac and disconnecting the time machine have no effect. I have no access to the normal tool bar. I want outa here.  Help!

    As always.. pondini to the rescue..
    http://pondini.org/TM/D6.html
    (I got there via google search.. took less time than to type this reply).

Maybe you are looking for