Removing ovals and lines???

SOS SOS SOS SOS

I’m writing a game of Twixt for my design assignment this semester in college. Part of the game requires you to bridge two points. This I can do. However how do you remove an oval and line that you’ve already drawn. Also this must be done without affecting any of the other ovals and lines already drawn! I’m using a JPanel to draw onto by accessing it’s getGraphics() method in my MouseClicked event handler.

Any help/advise anyone could offer would be great, thanks.

Redraw the same line but using the background color…

I guess you’re just drawing the new items on top of the current graphics without erasing what’s already drawn?

What you need to do is keep a list of all the things you’re drawing, and clear the screen each frame before drawing all items. To remove an item you have already drawn is then trivial - just remove it from the list of things to draw!

or, far simpler, you could set xor mode to a color, and draw the line.
To undraw the line, set xor mode to the same color,
and draw the same line a second time.

see. Graphics.setXORMode(Color c1)