paint color problem

I

Ian Stanley

Hi,
I am having a problem tyring to draw shapes and keep their original color
after transforming them.
For example:
when creating a ellipse I set the color to red
when creating a general path (hexagon) I set the color to blue.
The problem is after applying a transform such as a rotation or scale on a
an ellipse the original ellipse is now drawn(repainted) in blue - the
generalpath color. (I think I understand that a transformed shape must be
converted to a general path)
I have called my hexagon hexg but it appears as an instance of
GeneralPath. - Which is the conflict and the main part of my problem as any
transformed shape is re-drawn blue.
I want to be able to click on a shape and transform it maybe several times
while keeping its original color
I have tried everything from creating vectors of both colors and shapes and
trying to determine which shape was clicked on and saving that color.
Can anyone please suggest a way to fix this problem.
my paint component is below
public void paintComponent(Graphics gr)
{
super.paintComponent(gr);
Graphics2D g = (Graphics2D)gr;
for(int i=0; i<v.size(); i++){
if((Shape)v.elementAt(i) instanceof Ellipse2D.Float){
g.setColor(Color.red);
}
if((Shape)v.elementAt(i) instanceof GeneralPath){
g.setColor(Color.blue);
}
g.draw((Shape)v.elementAt(i));
}
}
Thanking you in advance
Ian
 
D

David Zimmerman

Ian said:
Hi,
I am having a problem tyring to draw shapes and keep their original color
after transforming them.
For example:
when creating a ellipse I set the color to red
when creating a general path (hexagon) I set the color to blue.
The problem is after applying a transform such as a rotation or scale on a
an ellipse the original ellipse is now drawn(repainted) in blue - the
generalpath color. (I think I understand that a transformed shape must be
converted to a general path)

Shapes don't have colors. They draw in the current color
 
N

Neomorph

Hi,
I am having a problem tyring to draw shapes and keep their original color
after transforming them.
For example:

public void paintComponent(Graphics gr)
{
super.paintComponent(gr);
Graphics2D g = (Graphics2D)gr;
for(int i=0; i<v.size(); i++){
if((Shape)v.elementAt(i) instanceof Ellipse2D.Float){
g.setColor(Color.red);
}

If Ellipse2D.Float is an instance of GeneralPath, the here is hwere the
color is reset to blue - you should put an 'else'in between to keep the
second if from performing when the first if has been found to be true.
if((Shape)v.elementAt(i) instanceof GeneralPath){
g.setColor(Color.blue);
}
g.draw((Shape)v.elementAt(i));
}
}
Thanking you in advance
Ian

Cheers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top