The one way I used to erase the last object drawn on an image was to keep a copy of the image being drawn on and using the
GC gc = new GC(canvas);
gc.drawImage(savedimg, x, y, w, h, x, y, w, h);
This copies a rectangle from savedimg to the canvas.
If you want to undo more than one event then you need to save copies of the area being drawn on in memory or on disk.
This is from my limited adventures into writing drawning programs in java.
You might look at http://alistairdickie.com/
at the free java drawing program thier for ideas.