• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use color variable in if else statement

 
Greenhorn
Posts: 6
Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for my mistake about the attribution.
 
I'm just a poor boy, I need no sympathy, because I'm easy come, easy go, little high, little low, little ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic