QUOTE(Feebz @ 12 Sep, 2008 - 09:02 AM)

CODE
class ShapePanel extends JPanel {
Shape currentShape;
public void setShape(Shape shape) {
currentShape = shape; repaint();
}
public void update(Graphics g) {
paint(g);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (currentShape != null) currentShape.draw(g);
}
}
This is called whenever I want to draw a shape to a JPanel. However, everytime it is done, the panel removes all previous drawings, which is not what I intended to be. How do I do it?
replace
CODE
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (currentShape != null) currentShape.draw(g);
}
by
CODE
public void paint(Graphics g) {
super.paint(g);
if (currentShape != null) currentShape.draw(g);
}
Actually never saw a situation where paintComponent() had to be overload