wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes changing colors in an if statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "changing colors in an if statement" Watch "changing colors in an if statement" New topic
Author

changing colors in an if statement

Rob Michaelson
Ranch Hand

Joined: Jul 15, 2003
Posts: 36
Hello
I want to change the color of the shapes in my code to something more fun but it isn't working. I would like to use web safe colors such as FF3300 or something to that effect. I know I need to do sonmething like .setColor(new Color(0xFF,0x33,ox00)); etc etc but it (the color stays red when I did it to the last current shape. Any suggestions?

Thanks
Rob
Jaunty John
Greenhorn

Joined: Jul 14, 2002
Posts: 21
Try this:
public void midAction()
{
// This method changes the color of the currently focused shape
// from blue to red, red to green, and green to blue
Color currentColor;
currentColor = currentShape.getColor();
if(currentColor.equals(Color.green) currentShape.setColor(Color.blue);
else if(currentColor.equals(Color.red) currentShape.setColor(Color.green);
else if(currentColor.equals(Color.blue) currentShape.setColor(Color.red);
// Repaint the window to show the change
win.repaint();
}
Cheers
JohnB


(((o o)))<br />""--^--"" Entropy is Increasing...
Rob Michaelson
Ranch Hand

Joined: Jul 15, 2003
Posts: 36
Oh I think what I needed to say is that I want to REPLACE blue,green,red with a web safe color to make it more intersting but its not working
Rob
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Well, 0xff, 0x33, 0x00 is going to be very similar to Color.red, which is 0xff, 0x00, 0x00; they may look identical to you. Why not try something more significantly different while you're testing? 0xff, 0x33, 0xff is purply pink, for instance.


[Jess in Action][AskingGoodQuestions]
Rob Michaelson
Ranch Hand

Joined: Jul 15, 2003
Posts: 36
Right - I will pick the colors later but syntactically I want to get it correct
Rob
Rob Michaelson
Ranch Hand

Joined: Jul 15, 2003
Posts: 36
Here's the problem - any suggestions?

I can't (or don't know how) to change "==Color.blue" to a web safe color for this to work
the
Jaunty John
Greenhorn

Joined: Jul 14, 2002
Posts: 21
I think this is what you are looking for???
The values, (0, 51, 255) are integer values representing the rgb values
JohnB
//~ Formatted by jFormatïż½2003 EMail: jlbalder@netscape.net 2003.07.24
...previous code
public void midAction() {
// This method changes the color of the currently focused shape
// from blue to red, red to green, and green to blue
Color currentColor;
Color ROSE = new Color(255, 0, 51);//Colors NOT accurate!
Color FROG = new Color(0, 255, 51);
Color NAVY = new Color(0, 51, 255);
currentColor = currentShape.getColor();
if(currentColor.equals(Color.green)) currentShape.setColor(NAVY);
else if(currentColor.equals(Color.red)) currentShape.setColor(FROG);
else if(currentColor.equals(Color.blue)) currentShape.setColor(ROSE);
// Repaint the window to show the change
win.repaint();
}//~public void midAction()...
more code...
Rob Michaelson
Ranch Hand

Joined: Jul 15, 2003
Posts: 36
Hey
Thanks Jaunty - I will try that shortly-- I appreciate it!
Rob
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changing colors in an if statement