Re: If with colors
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 13:44:34 GMT
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
.
- References:
- If with colors
- From: bjorn . wallstrom
- If with colors
- Prev by Date: Re: class file has wrong version 49.0, should be 48.0
- Next by Date: Re: Newbie: -classpath option of java does not load the content of the jar file
- Previous by thread: Re: If with colors
- Next by thread: XML JDOM problems
- Index(es):