Hi Experts: I have a class which extends JPanel now ShapePanel (Sp) this gets added to a normal JPanel (Container) which inturn gets Added To JFrame (Window). In the paintComponent method i draw a shape.... but the shape never persists after rendering. In the debugger i can see that it gets re-drawn every time i resize or something like that.
Now i overloaded the JPanel's (Sp's) paintComponent and added this
super.paintComponent(g);
ShapeDrawerGui SdG = new ShapeDrawerGui((Graphics2D)this.getGraphics());
//for(Shape s : ArrayOfShapes)
{
if(s instanceof Rectangle)
SdG.Paint((Rectangle)s);
else if(s instanceof Triangle)
SdG.Paint((Triangle)s);
else
SdG.Paint((Circle)s);
} //s is a custom-shape object
the graphics object comes from (obviously) the JPanel....
But the drawn image never stays on the panel - you see it for a split second and its gone...
I have done some searching but to no avail.
The actual Drawing
public ShapeDrawerGui(Graphics2D _g)
{
g = _g;
g.setColor(Color.Black);
}
@Override
public void Paint(Circle c)
{
g.drawArc(0, 0, 50, 50, 0, 360);
}
@Override
public void Paint(Triangle t)
{
Polygon p = new Polygon();
p.addPoint(0, 25);
p.addPoint(0 , 50);
p.addPoint(50, 50);
g.drawPolygon(p);
}
@Override
public void Paint(Rectangle r)
{
g.drawRect(0, 0, 50, 50);
}
Kind regards
Markus