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
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