Using Java, I generate a new JFrame frame and load an image into it along with some buttons:

I then click on ‘Classify’ in order to detect the main area of interest and this produces an image such as the following:

However, when I click ‘Classify’ once again, the first drawings (green and red circles) remain on the image and they are then classified. How can I do it so that when I click ‘Classify’ for a second/third/n-th time, the image is reset (all drawings/circles removed) back how it was before ‘Classify’ was clicked?
I have a ‘Reset Image’ JButton, but I have yet to implement this (hence my question!).
Many thanks.
Memory usage efficiency aside, you could store the initial graphics state into a
BufferedImage. And upon clicking Classify, draw onto a copy of theGraphicsobject of that image instead, and then paint the area with it.And upon clicking Reset Image, just draw the image directly to the area.