-
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?
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks