Problem with Shapes / GeneralPath;
Hi,
I am drawing some shapes usind GeneralPath; these shapes are in a separate class. Due to a misunderstanding I had some problems with that, however itchyscratchy helped me with that in this thread (see reply #12): http://forum.java.sun.com/thread.jspa?threadID=5151744 (thanks again!)
I now have the following code (following the sample posted by itchyscratchy)
publicclass MyShapes
{
privatefinal Shape bird = createBird();
privatefinal Shape fish = createFish();
publicfinal Shape getBird()
{
return this.bird;
}
publicfinal Shape getFish()
{
return this.fish;
}
privatefinal Shape createBird()
{
GeneralPath p =new GeneralPath();
// lineTo() etc
return p;
}
// Similar code for the fish, etc
privatefinal Shape createFish()
{
GeneralPath p =new GeneralPath();
// lineTo() etc
return p;
}
}
I declared various shapes. Whenever I draw a shape in one of the other classes,all shapes are being drawn. There must be a bug somewhere, unfortunately I can't find it.
publicclass PMgmtextends JComponent{
privatestaticfinallong serialVersionUID = 1;
private MyShapes ms =new MyShapes();
(...)
protectedvoid paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.BLACK);
g2.draw(ms.getBird());// all shapes are being drawn, not only Bird :(
(...)
}
}
Thanks for your help!

