// Like Fig. 10.21
// Scribble.java

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Scribble extends Applet {
   private int xpos, ypos;

   public void init() {
     addMouseMotionListener( new MotionHandler( this ) );
   }

   // set the drawing coordinates and repaint
  public void setCoordinates( int x, int y ) {
    xpos = x;
    ypos = y;
    Graphics g = getGraphics();
    g.fillArc(xpos, ypos, 4, 4, 0, 360);  
  }
}

// Class to handle only mouse drag events for the Drag applet
class MotionHandler extends MouseMotionAdapter {
  private Scribble scribble;

  public MotionHandler( Scribble s ) {
    scribble = s; 
  }

  public void mouseDragged( MouseEvent e ) {
    scribble.setCoordinates( e.getX(), e.getY() );
  }
}
