Chapter 2 - EventListeners
3. The MouseMotionListener
/* MouseMotionListener will enable you to performactions when the mouse moves over
a hotspot. You can also use this to drag things,that will require MouseListener and
MouseMotionListener at the same time.
This applet will show a rectangle that will changecolor when the mouse moves over it.
It's basically the same as the previous one.
// Tells the applet you will be using the MouseMotionListenermethods.
public class MouseMotionExample extends Applet implements MouseMotionListener
// wll be true when the Mouse is in theRectangle
public void init()
rect1xco = 20;
// Add the MouseMotionListener to yourapplet
public void paint(Graphics g)
// This will show the coordinates of themouse
/* If you use MouseMotionListener then these methodshave
to be here
// This will be excuted whenever the mousemoves
in the applet
// This is works like mouseMoved but onlywhen
the mouse is being pressed
/* It's quite easy, but this isn't a good exampleof
Home - Chapter 1- Chapter2 - Chapter3 - Chapter4