I want to draw in response to mouse events. The only way I know how to draw is using a Graphics2D object, as passed to paintComponent(). I tried saving that object in an instance variable, and then using it in mouse event handlers, but no drawing occurs. What am I doing wrong?
Is there a way to get a Graphics2D object from a panel or a frame? Where does paintComponent() get invoked and where does the Graphics2D object come from?