Re: If with colors



On Wed, 27 Jun 2007 03:35:17 -0700, bjorn.wallstrom@xxxxxxxxx wrote,
quoted or indirectly quoted someone who said :

I try to test what vale a color variable has with

if (myColor==Color.green)

and even when I know it is true it doesn't work, any idea how I could
solve this?

Presuming myColour is of type Color, you should be using

if ( myColor.equals( Color.green ) )

UNLESS you are absolutely sure myColor was initialised with

myColor = Color.green;

rather than say:

myColor = new Color( 0x00ff00 );

You get into similar problems with equals vs == with Strings.
See http://mindprod.com/jgloss/gotchas.html#COMPARISON
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.