I want to set up a grid of circles (non-overlapping) so that, when the mouse pointer is over one of them, that circle changes colour. I have experimented and so far have two options:
Use a container e.g. JPanel. Use MouseMotionListener.mouseMoved(MouseEvent e) to get the x and y coordinates of the mouse pointer at all times. Then, if the coordinates lie within one of the circles, use repaint() to repaint the whole container.
Set each circle as a container. Use MouseListener.mouseEntered(MouseEvent e) to detect when the mouse pointer moves over a circle. Then redraw that container only.
Is #2 the best approach? If so, how can I set up a circular container? Is there a better approach than either of the above?