• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use color variable in if else statement

 
Sarah Qazi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[size=12]Hi,

Can anyone tell me the syntax to use Color variable in if else statement. I am getting the error Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.awt.Color
at this line.

Col is color variable. [/size]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are getting that error message because you didn't check the red marks on Eclipse before compiling. Go back to the source code and hold your mouse over the red mark and see what the error in the little dropdown is.
 
Sarah Qazi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is showing that cannot find awt class in java package but i think that there is problem with my syntax.
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarah Qazi wrote:It is showing that cannot find awt class in java package but i think that there is problem with my syntax.

Yes, perhaps you meant

?

P.S You should use the equals method when comparing non primitives.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you had sorted out that import you would have got rid of the compiler error: import java.awt.Color; not import java.Color; If you had clicked on the red mark it would probably have suggested that change.
It would not have pointed out the logic error of using == which Piet Souris has already told you about. There are more details in the Color class.
 
Piet Souris
Rancher
Posts: 1295
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was E. Armitage who pointed to the use of the equals-method, not me.

My stupid reaction was that the Color class doesn't override the 'equals'method, so the easiest thing
would be to use the Color.getRGB() method. But, when looking at the Color API, to my shame
I noticed my blunder. I tried to delete my respons, but as I said, I couldn't. So, never too old to blunder,
I guess...

So, to clarify: after getting the import correct, Sarah should use:



Greetz,
Piet
 
Campbell Ritchie
Sheriff
Pie
Posts: 49361
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for my mistake about the attribution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic