// We must generally import all of these libraries into
// any applet. The "java.__" is the name of the library,
// and the * indicates that we are laoding all classes
// in that library.

import java.awt.*;        // Java visual tools
import java.awt.event.*;  // Java visual events
import java.applet.*;     // Java applet classes

// This defines the Scribble class (we will be adding a Scribble
// applet to our page). The class extends the Applet class (that
// is, it inherits all abilities of Applets in general to be drawn
// on web pages, etc.). It implements the MouseMotionListener
// interface, which means it will have methods for responding to
// the events of moving and dragging the mouse.

public class Scribble extends Applet
                      implements MouseMotionListener {

  // The init() method is automatically called when the applet
  // is loaded. It is where you want to put code related to
  // initializing the applet.

  public void init() {

    // This tell the browser to notify "this" applet when a
    // mouse motion event occurs.

    addMouseMotionListener(this);
    }

  // This method will be called by the browser when the mouse is
  // dragged on the surface of the applet. The MouseEvent parameter
  // is like the event object in DOM -- it contains useful data
  // about the nature of the event.

  public void mouseDragged(MouseEvent e) {

    // We can execute the getX() and getY() methods on the MouseEvent
    // object to find where the mouse is.

    int x = e.getX();
    int y = e.getY();

    // The Graphics object is a component of the applet that represents
    // the "visible drawing surface of the applet. We must get it
    // and draw on it to make things visible.

    Graphics g = getGraphics();

    // fillOval is one of the simple methods of the Graphics object.
    // Its parameters are the X and Y coordinates of the upper left
    // corner of the oval to draw, and the height and width of the oval
    // (in pixels). In this case, we are drawing a solid circle 5
    // pixels wide centered at the mouse location.

    g.fillOval(x-2, y-2, 5, 5);

    }

  // Even though we don't do anything when the mouse is moved (and
  // not dragged, we still must (trivially) define a method for this,
  // as the compiler expects us to define ALL methods related to mouse
  // motion.

  public void mouseMoved(MouseEvent e) {}
  }

