Using Mouse Events for User Interaction
We set up a test program that creates three movable objects, a rectangle, circle and triangle, as in the earlier example. In this program, we start with them all cyan. Whenever the mouse is detected to be over one of the objects, its color is changed to red. If the mouse button is used to drag the object, we move the object to the mouse location.
Note that it is not necessary to introduce a thread for this applet since it is not running continuously - it is mostly waiting for mouse events.