Prev Up Next
Go backward to Variations on a Theme
Go up to Top
Go forward to Adding an Applet to a Web Page

Tracking Mouse Movement

The skeletal applet we gave you to start with contains four additional (currently empty) methods:

mouseMove
which should contain instructions telling the computer what your applet wants it to do when the mouse is moved while its button is not depressed. Within this method (and within mouseDrag), the names "x" and "y" can be used to refer to the coordinates of the pixel to which the mouse was moved.
mouseDrag
which determines the actions performed when the mouse is moved with the button depressed.
mouseExit
which contains instructions the computer should follow when the mouse moves out of the applet's screen region (i.e. out of the AppletViewer window).
mouseEnter
which instructs the computer how to behave when the mouse is moved back into the applet's screen region.

By adding some instructions to these methods, we can produce a more responsive applet.

With the current version of your applet, the computer will often leave just a fraction of your message readable with the rest lost off the edge of the window when you move the mouse out of the window. Let's fix this by cleaning things up when the mouse leaves the window.

There are many more variations of these simple applets you could try. For those who are inspired, we include details of some other variations of the commands you have used and some additional commands you can include in a method at the end of this document. We encourage you to experiment with these possibilities on your own.

For now, however, we ask you to leave your applet as it is and move on to learn how to get it to run under a web browser as part of a web page. So, "Quit" both the "AppletViewer" and the Metrowerks editor leaving your computer back at the Macintosh desktop in the Finder.


Prev Up Next