Results 1 to 4 of 4
  1. #1
    Lets Assume is offline Assuming
    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Question Declaring a variable for JOptionPane

    I'm having a bit of trouble with this. It's killing me. The code below is a method for when a button is pressed. I need to declare the variable ("option") but I'm not sure where to do so. Or the code to do it. I've been having trouble with this for the past hour. Any help is appreciated.

    Java Code:
      public void button_B1()  {
        
        JOptionPane.showConfirmDialog(null, "You have chosen Intel's Core i3-3220 Ivy Bridge 3.3GHz LGA 1155 55W Dual-Core Desktop Processor. Are you sure?","Confirm your Processor Choice",JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION )
        {
          L3.setText("You have chosen Intel");
        }
        else if (option == JOptionPane.NO_OPTION) 
        {
          
        }
    It needs to be so when YES is pressed, my L3 panel changes the text. Like I said, option needs declared. Any help greatly appreciated.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,322
    Rep Power
    5

    Default Re: Declaring a variable for JOptionPane

    The option value to which you are comparing is returned by the JOptionPane.showConfirmDialog method call. In your code you are not assigning anything from the JOptionPane call.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Lets Assume is offline Assuming
    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Default Re: Declaring a variable for JOptionPane

    Quote Originally Posted by jim829 View Post
    The option value to which you are comparing is returned by the JOptionPane.showConfirmDialog method call. In your code you are not assigning anything from the JOptionPane call.

    Regards,
    Jim
    soooo,

    Java Code:
    int option = JOptionPane.showConfirmDialog(null,"","",JOptionPane.YES_NO_OPTION);
    AWESOME. That worked, thanks a bunch Jim. :D I repped you.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Declaring a variable for JOptionPane

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Need help declaring array
    By earnest in forum New To Java
    Replies: 7
    Last Post: 02-22-2011, 12:17 AM
  2. Declaring a Variable for RGB swaps? Dr Java
    By brandnew956 in forum New To Java
    Replies: 5
    Last Post: 03-03-2010, 01:44 AM
  3. declaring classes
    By coltragon in forum New To Java
    Replies: 17
    Last Post: 12-21-2009, 06:20 PM
  4. Declaring Interface
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-08-2007, 08:41 AM
  5. Declaring Enumeration
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-04-2007, 05:59 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
  •