Noel Enete
Touching Java Windows

Every time the mouse is moved or clicked on an applet, an object (called an event) is created that describes what occured.

Minimalist Mouse Example

This example traps each of the mouse messages and writes a message to standard output when each one is received.

Figure 1: TouchWindow1 (execution)

Moving Text Example

This example uses the mouse messages to keep track of the current mouse position and writes a string of text to that spot. As the mouse is moved over the applet, the text appears to be attached to the mouse pointer.

Figure 2: TouchWindow2 (execution)

Moving Sparkler Example

This example uses the current position of the mouse as the point from which to draw a number of lines in random directions with random colors. When the mouse is moved, there appears to be a sparkler attached to the mouse pointer. When the mouse is dragged, the lines become completely random and they appear like tinker toys.

Figure 3: TouchWindow3 (execution)

Moving and Targeting Image Example

This example demonstrates how to draw an image on the screen and move it around using mouse messages.

Figure 4: TouchWindow4 (execution)

© Noel Enete, 1997 . . .