JOptionPane and if (a.equals.. problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JOptionPane and if (a.equals.. problem

  1. #1
    Join Date
    Sep 2004
    Posts
    59

    JOptionPane and if (a.equals.. problem

    Ive got this problem:

    I cant compile the application because of this error:
    int cannot be dereferenced
    if (Select.equals ("Hard")) {

    So the problem should he around here:

    Select = JOptionPane.showOptionDialog(f, "Begin game", "Select difficulty", JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE, null, BeginGame,BeginGame[1]);

    if (Select.equals ("Hard")) {
    System.out.println("hard");
    }
    else {
    System.out.println("");
    }


    Could it be that equals has problems getting info about what option has been choosed?
    My own java video tutorials, feel free to watch it.
    http://www.engineeringserver.com/for...amming-b311.0/ Need java help? For beginning and intermediate java coders!

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    I think you want to use the showInputDialog of JOptionPane. The one you use
    return an int representing the selected option. E.g you are trying to
    invoke (dereference) a method from an int, and a plain java int
    does not have any methods, - its not an object.

    showInputDialog returns an Object or a String depending on the type of parameter list
    (method signature) you use. If you choose the one that returns an Object you will
    have to typecast it to String (if that is what you are aiming for), like:

    String selectedOpt=(String)JOptionPane.showInputDialog(....);
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center