JOptionPane: which Button was pressed ?

Hello,
I created a JOptionPane with a yes- and a no-Button, but I don't know how to find out which Button was pressed by the user. Can anybody help me ?
Thanx,
Findus

There are constants on JOptionPane that you can use to tell what button was pressed. When one of the showXxxDialog methods returns an integer (indicating which button was pressed by the user), the possible values are:
YES_OPTION
NO_OPTION
CANCEL_OPTION
OK_OPTION
CLOSED_OPTION
For instance:
int ret = JOptionPane.showConfirmDialog(myFrame,
                                    "This is a  message",
                                    "Select An Option",
                                    JOptionPane.YES_NO_OPTION,
                                    JOptionPane.QUESTION_MESSAGE);
if (ret == JOptionPane.YES_OPTION) { ... }
else if (ret == JOptionPane.NO_OPTION) { ... }
// etc...

Similar Messages

  • How do I find out which tab was pressed?

    Our site is using tabs. We have few portlets in different tabs whose custom rendering depends on which tab the user has clicked.
    Programmatically, how do we find out which tab was pressed?
    We're using portal 9.0.4. Thanks for your help.
    Ashraf

    Thanks Sanjay for your quick reply!
    Option 2 looks like a potential solution. Not quite elegant as you indicated, but will work.
    I recall reading somewhere, before the release of 9.0.2.6, that in upcoming version 9.0.2.6/9.0.4 you should be able to programmatically determine the last tab clicked. If you could kindly confirm whether no such built-in mechanism (API, etc.) exist to find out last tab clicked in portal version 9.0.4? We're looking to implement this feature in database provider environment.
    Thanks again for your help.
    Ashraf

  • Servlet: How do I know which button was pushed?

    Hi All,
    I have a web page that has two buttons on it, one to log out and to other to retrieve items (HTML is below). I have a servlet that receives the HTTP Respone/Request and passes the Config and Request to an BasicHandlerManager class that will look to see which button was pushed and then perform an action based on the button that was pushed. Well, in the BasicHandlerManager class I do not know how to determine which button on the web page was pushed. How do I determine that? I've found that they 'if' and 'else if' that contains the "Logout" and "Retrieve" always executes the 'if' statement and never the 'else if'. When I swap the "Logout" and "Retrieve" that are in the 'if' 'else if' statement it will still execute the 'if' and not the 'else if'. So, how do I determine which of the 2 buttons was pushed on the web page?
    Here's my HTML and some code from the BasicHandlerManager.
    Thanks for your help.
    HTML Code:
    <INPUT TYPE="HIDDEN" NAME="requestID" VALUE="HOMEPAGE">
    <INPUT TYPE="SUBMIT" NAME="Retrieve" VALUE="Retrieve">
    <INPUT TYPE="SUBMIT" NAME="Logout" VALUE="Logout">
    BasicHandlerManager Class:
    BasicHandler handler = null;
    if (request != null)
        String strRequestID = request.getParameter("requestID");
            if (strRequestID != null)
                if (strRequestID.equals("LOGIN"))
                    handler = new AccountDelegate(config);
                else if (strRequestID.equals("HOMEPAGE"))
                    if (request.getParameter("Logout").equals("Logout"))
                        handler = new Logout(config);
                    else if (request.getParameter("Retrieve").equals("Retrieve"))
                        handler = new ProductDelegate(config);
                if (handler == null)
                    handler = new DefaultHandler(config);
            } // end if (strRequestID != null)
    } // end if (request != null)
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    First change your buttons so they have the same name
    thus
    <INPUT TYPE="HIDDEN" NAME="requestID" VALUE="HOMEPAGE">
    <INPUT TYPE="SUBMIT" NAME="Retrieve" VALUE="Retrieve">
    <INPUT TYPE="SUBMIT" NAME="Logout" VALUE="Logout">
    becomes
    <INPUT TYPE="HIDDEN" NAME="requestID" VALUE="HOMEPAGE">
    <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Retrieve">
    <INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Logout">
    Now in your servlet you will want something akin to the following.
         public void performTask(
              HttpServletRequest request,
              HttpServletResponse response)
              throws ServletException, IOException {
              String action = request.getParameter("SUBMIT") ;
              if( "Retrieve".equals(action) ){
                   //     Perform whatever operation needs to be done on Retrieve
              else if( "Logout".equals(action) ){
                   //     Perform whatever operation needs to be done on Logout
              else {
                   //     Perform whatever operation needs to be done if all else fails
         }By giving your buttons different names, which seems like a really good idea at the outset, you give them different parameter names in the request which A) takes up more space in the request and B) means you have to check both parameters. These are essentially the same action (Submitting) so you use the Value to retrieve the action indicated by the button.
    Regards,

  • How to find out which button is pressed in a form?

    I want to know which button (Insert, Update, Delete) the user has pressed in a form in Portal 9.0.2.3.
    My form is launched so that the ID column is fixed (and hidden). Unfortunately when user presses Insert, the value of the ID is lost. I have tried to work-around this by calling the form again after successful submission. And also I'm trying to improve actions so that the form window is closed if Update or Delete is pressed.
    I have got some solutions from Metalink. My problem is that they not working all the time. E.g. solution below worked this morning, but not anymore (after I have changed the form)! Have I made errors or are solutions shown in Metalink only for Portal v3.xx?
    My code in 'On successful submission of a from..' field:
    DECLARE
    l_action varchar2(20);
    v_id number;
    BEGIN
    -- get the action performed
    l_action := p_session.get_value_as_varchar2(
    p_block_name =&gt; 'DEFAULT',
    p_index =&gt; 1,
    p_attribute_name =&gt; '_STATUS');
    -- If the action is insert then call this form again
    -- If the action is update or delete then close this window
    if (l_action = 'Inserted one record.') then
    v_id := p_session.get_value_as_number(
    p_block_name =&gt; 'DEFAULT',
    p_index =&gt; 1,
    p_attribute_name =&gt; 'A_ID');
    go(PORTAL.wwv_user_utilities.get_url('PROVIDER.LINK_TO_FORM', 'id', v_id));
    else
    go('http://server/closewindow.htm');
    end if;
    END;
    When debugging the code, variable l_action is always null.
    Best regards
    Rainer

    Hi Satish,
    Check this blog -
    /people/alwin.vandeput2/blog/2006/04/13/how-to-search-for-badis-trace-it
    Check Clemens reply in this thread, its great-
    BADI
    <b>Reward Points if this helps,</b>
    Satish

  • Which hyperlink was pressed

    hi,
    i have one jsp page (ie /example.jsp) which contains many hyper links which link back to (/example.jsp).
    the only thing i want to know is this that which hyper link was pressed for coming back to the page /example.jsp.
    well it might sound stupid but its requriement n im not too much skilled...
    thanks
    bye

    To all the hyperlinks add some extra parameters to identify that link.
    Like this
    examples.jsp?param=1
    examples.jsp?param=2
    examples.jsp?param=3
    examples.jsp?param=4
    etc.

  • My ipod touch will not work the screen is black with a small white circle/wheel in the middle of it no matter which button i press and hold nothing happens

    My ipod touch stopped working. The screen is black with a small white circle/wheel with ridges/teeth in the middle of the screen. No matter what button is pressed and/or held nothing happenes. Can anyone assist me?

    Try the remaining items of:
    iOS: Not responding or does not turn on
    If not successful and you can't turn the iPod fully off, let the battery fully drain. After charging for at least and hour try again.
    - If still problem time for an appointment at the Genius Bar of an Apple store.

  • When I try to select bookmarks I am stymied because the mouse control is overridden. This became a recent problem. The way it worked in the past is that items were selected only when left mouse button was pressed.

    I select from bookmarks menu a folder containing folders & bookmarks, but I cannot select what I want because an automatic action occurs where my mouse cursor is right then. Selecting what I want from the list is impossible as an undesired selection opens inadvertently, without me any positive action by clicking left mouse button. This problem did not exist 6 months ago. This is now a big problem for me. I'm going to stop using FireFox if this problem cannot be fixed soon!

    You do not delete bookmarks in the Customize window.
    You need to open the Library if you want to delete bookmarks.
    *Bookmarks > Show All Bookmarks
    * https://support.mozilla.com/kb/Deleting+Bookmarks

  • Need help with Cluster of Buttons displaying a message to which button is being pressed.

    Create a VI with a cluster of six buttons labeled Option1…Option6. When executing, the VI should wait for the user to press one of the buttons. When a button is pressed, use the Display Message To User Express VI to indicate which option was selected. Repeat this process until the user presses the Stop button. The parameters of the problem needs me to use a while loop, case structure, a shift register and search 1d array. I'm just having trouble setting up my case structures and how to get the search 1d array to work with the cluster to find which button was pressed. I've attached a picture of my VI and also a VI I made without the cluster that does what I want the Cluster VI to do which is to recognize the button being pressed and bring up a prompt.
    Solved!
    Go to Solution.
    Attachments:
    Button Pressed.jpg ‏127 KB
    Buttons Pressed No Cluster.jpg ‏189 KB

    Okay so i moved the cluster into the while loop and wired a boolean true constant to the element of the search 1d array and now I can at least get the prompt for button 1 to display, but when I press the other buttons which I have set up the same way as button 1 I get no prompts so how can I get it to recognize the other buttons. Am I implementing the shift register incorrectly? 
    Attachments:
    Button Pressed 2.jpg ‏115 KB

  • Determine which button is clicked

    I am creating the download buttons on my page dynamically and I am assigning the name also dynamically attaching the counter with the name. Now On form post, i want to know which button( button at which counter ) was being pressed. Could u help me on this.

    Use request.getParameterNames( ) to get an enumeration of all the names passed by the form. You can then go through the list and determine which button was pressed since the name of that button would be passed along.
    If you are uncomfortable with using the enumeration technique, do a request.getParameter( button_name ) for each button and check whether you get a null value which implies the button wasn't pressed, or the counter value, which implies the button was pressed. If you have a lot of buttons, this results in some redundant code, but if you have only one or three, then this is probably an ok way to do it.

  • My iPhone 4S has stuck some how. It won't allow me yo swipe but tells me which button I am pressing! How do I get out of this, tried the usual, on off and holding both to reset but still stuck

    My iPhone 4S has stuck and won't allow me to swipe it open! It talks to me and tells me which button I'm pressing, tried to reset ect but not working,

    Sounds like you've switched on something under accessibility, I have an iPhone 5s & there it's under settings>General>accessibility.
    To swipe you could try using two fingers.
    Hth,
    Message was edited by: Doctor9fan

  • User Exit which runs after pressing SAVE button at VF01 Screen.

    Dear all,
    I need user Exit which runs after pressing SAVE button at VF01 Screen.
    Kind Regards,

    If you search the forum, you can find plenty of threads on this, for example Re: Badi or user exit for VF01 while save Can you let the forum know what exactly you want to achieve using user exit during saving of a billing document?
    Regards,

  • I want to create a vb form in which when i pressed a button then a specific song must be played.

    i want to create a vb form in which when i pressed a button then a
    specific song must be played. will u plx help me to do this..what i mean is that when i pressed that button a audio msut be played. will anyone help

    i want to create a vb form in which when i pressed a button then a specific
    song must be played. will u plx help me to do this..what i mean is that when i pressed that button a audio msut be played. will anyone help
    My.Computer.Audio.Play("C:\Users\John\Desktop\Something.Wav",
    AudioPlayMode.Background) or My.Computer.Audio.Play(My.Resources.SomeWavFileinyourresources,
    AudioPlayMode.Background) will play .Wav files only. And it will play them directly from resources without having to write them to disk to play them first.
    The
    Windows Media Player Control (can be created dynamically and not displayed) or the
    Media Player Class or a third party control that you can download called
    VLC Media Player can all play audio files based on the Codecs they use or have installed. Which would be .Wav, .MP3 and some others as well as you can download third party Codecs that can be provided to your system possibly for the Media Player class to
    use but as plugins I believe for Windows Media Player and VLC Media Player I believe for playing other types of audio and video file formats that they do not directly support with their installed codecs. Although all of these require that a file is available
    from disk or thumbdrive or CD Rom to play and can not directly play resources therefore resources must be written to disk in order to work.
    Microsoft Visual Basic language forum search results for "WindowsMediaPlayer"
    Microsoft Visual Basic language forum search results for "MediaPlayer"
    La vida loca

  • Hi I was wondering if you could help me I have an iPhone 4 which the silent/ringer button was broken and I had ordered a repair when receiving the box I was juggling a lot and dropped my phone in water will my warranty cover the damages?

    Ho there I have an iPhone 4 and is currently away for service but I wondered if it will be covered by the warranty as the silent button was broken and I sent for a box and as the box was being delivered I was juggling a lot and dropped my phone in water. I  wondering if it will be covered due to the fact the button was broke before the water damage.
    Thanks

    Most likely not but only Apple can say for sure.

  • Add point to scatter plot each time a button is pressed

    Hi folks,
    Apologies if this has been answered elsewhere, I am new to LabVIEW and trying to get an experiment up-and-running quickly!
    I was wondering if anybody would have general pointers or code examples on how to create a 2D scatter plot, to which a data point is added each time a button is pressed.
    I am measuring a gauge pressure and a force (from a load cell). I would like the scatter plot to add another data point each time I press a button, so that a history of my datapoints is shown. It would also be quite nice is this plot could then be exported as a .jpg using another button, but this is not critical. 
    A seperate button would also be available to clear the scatter plot.
    My current thinking is that this can be done by 'adding to an array', - presumably the chart would refresh each time an element was added to the array, but I am struggling a little bit with how to do this.
    If anybody has any suggestions, I would be very grateful for them.
    Many thanks,
    Euan

    Hi Euan,
    If you want to have your data shown in real time (and I'm assuming you do) then you'll need to use a Waveform Chart. The chart is able to update itself each time a value is written to it.
    The event structure is your friend here: you can write a case to update the chart each time a button is pressed. You can also create cases for the other situations you mentioned (clear chart, export jpg etc.)
    If you don't care about the chart updating in real time then you can use your idea of updating an array and then use a Waveform Graph to plot the datapoints at the end of your program.
    Take a look at the LabVIEW Basics course and the Examples for info on how to implement the event structure. If you run into any problems just post your VI and we'll see if we can't help you fix them.
    -CC
    "If anyone needs me, I'll be in the Angry Dome!"

  • IPod Touch turns off when lock button is pressed.

    My father accidentally put my dog's cage on top of my iPod Touch...surprisingly it was fine. Or so I thought. A few minutes later the volume started acting strange, which I think was a problem with the button. Somehow I fixed that after playing around with it. But when I pressed the lock button, the iPod turned off, and wouldn't turn back on, as if it had no battery life whatsoever. When I got home, I plugged it in, and thankfully it responded. I thought it was fine, until I tried to press the lock button again. It completely dies every time the button is pressed. Which I suppose is alright, as long as I never press that button again but that's rather annoying. Any ideas on what to do with that?

    Sounds like you have a internal connection problem in the iPod. I would make an appointment at the Genius Bar of a local Apple store.

Maybe you are looking for

  • Desperate HELP with Random Numbes in an Array & Do / While

    Please somebody help, I have been working this problem for over 7 days now and can't get it. I have tried everything from a while to a do while to this and that. I need to have an Array of 8 that when run will produce random numbers for output betwee

  • VirtualMachine settings problem

    Hi, My new O9i JD is working using JDK1.3, while the development environment is set to JDK1.4. The problem is that during project starting(the compilation is OK) the following command is executed by JD: javaw -ojvm ... and the unsupported option "-oj

  • Catalog corruption when moving files in folder view

    LR 1.3.1 MacOS 10.5 (although also happened with 10.4) I've been using LR since the free beta and have over 6,000 images in my catalog. I shoot Nikon cameras almost always in RAW + JPEG. I used to add the jpegs as separate images, but now use them as

  • How do you change the stroke weight of a grouped object?

    I get frustrated with having to ungroup objects to change the line thickness. Is there a way of selecting a group of shapes and changing all of there line weights (if the same weight or different weights within the group) to a new line weight in one

  • Reports with java......

    hello everyone. i need to generate reports in my app. what tool should i use with java?? or i can use any tool to create reports?? thanx