If you forget to call super.paintComponent(g);, the background will not be cleared, so the old image will still be visible. And all JButton and everything you added will not be drawn. To fix this, let the panel draw first, then you can draw your stuff on top of it.
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
for (Shape i : myArr)
{
g2d.draw(i);
}
}
( , , DrawingPanel.add(..)). :
@Override
protected void paintComponent(Graphics g)
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.grey);
g2d.fillRect(0,0,this.getWidth(),this.getHeight());
for (Shape i : myArr)
{
g2d.draw(i);
}
}
.
if (buttonPress.buttonType.equals("Clear"))
{
myArr.clear();
repaint();
}
revalidate();.