Check out Custom Painting Approaches
It shows the two common ways to do this:
-
Keep an ArrayList of Objects to paint and then iterate through the List in the paintComponent() method.
-
Paint directly to a BufferedImage and then just display the BufferedImage.
solved Drawing an unknown number of shapes [closed]