Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing colors in an if statement

 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right - I will pick the colors later but syntactically I want to get it correct
Rob
 
Rob Michaelson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey
Thanks Jaunty - I will try that shortly-- I appreciate it!
Rob
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic