Clicking on an oval in JPanel
I am making a paint applet, which draws shapes on a 'canvas' by storing shapes into an arraylist (using the Graphics class).
I need to be able te erase complete shapes by clicking them with the eraser tool.
I managed to make this work for rectangles, filled rectangles and lines. I am not managing to do this with ovals. This because the radius is not equal along the entire circumference. How can I calculate whether a user clicked withing the oval, or on the (variable) stroke of an open oval?
For an example this is what the code for the filled rectangle:
// p1 and p2 are startpoint and endpoint (class vars).
// p is the point clicked by the user
// iMargin is the amount of pixel the user is allowed to miss the shape by (class var).
private boolean fillRectRaak(Point p)
if(p.x <= this.p2.x + iStroke + iMargin &&
p.x >= this.p1.x - iStroke - iMargin)
if(p.y <= this.p2.y + iStroke + iMargin &&
p.y >= this.p1.y - iStroke - iMargin)