File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to use color variable in if else statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to use color variable in if else statement" Watch "How to use color variable in if else statement" New topic
Author

How to use color variable in if else statement

Sarah Qazi
Greenhorn

Joined: Oct 18, 2013
Posts: 6
[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

Joined: Oct 13, 2005
Posts: 38818
    
  23
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

Joined: Oct 18, 2013
Posts: 6
It is showing that cannot find awt class in java package but i think that there is problem with my syntax.
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: Oct 13, 2005
Posts: 38818
    
  23
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
Ranch Hand

Joined: Mar 08, 2009
Posts: 545
    
  11
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

Joined: Oct 13, 2005
Posts: 38818
    
  23
Sorry for my mistake about the attribution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use color variable in if else statement