//From: Overland, Brian. Java in Plain English. Second Edition. 1997. page 53.
    
import java.awt.*;
import java.applet.*;
    
public class Scribble extends Applet 
{
    int oldX, oldY;
    
    public boolean mouseMove (Event evt, int x, int y)
    {  Graphics g = getGraphics();
       g.drawLine(oldX, oldY, x, y);
       g.dispose();
       oldX = x;
       oldY = y;
       return true;
    }
    
    public boolean mouseEnter(Event evt, int x, int y)
    {  oldX = x;
       oldY = y;
       return true;
    }
    
}
    
/* What's going on....
 * In most applets and applications, you use a graphics object within paint
 * and then forget about it. For certain kinds of applications, however, you 
 * need to grab the graphics object and do a quick operation directly to the 
 * display. The Scribble applet does just that: every time the mouse moves, 
 * Scribble grabs the graphics object and draws a line.
 * 
 * The Scribble applet has several features:
 * - it uses mouseMove() and mouseEnter() to handle mouse actions.
 * - It grabs the graphics object directly by calling the applet's getGraphics()
 *   method. Scribble would be too slow if you had to wait for a repaint after
 *   each mouse move.
 * - It releases the graphics object quickly by calling the graphics object's 
 *   dispose() method. This forces the release of the graphics context associated 
 *   with the object.
 * - The use of the dispose() method is why it runs so quickly. It ensures that
 *   the graphics context is immediately released back to the system. You can
 *   only reaccess the graphics object again after a call to getGraphics()
 */
   
	

