/**
 * RepaintApplet3a.java
 * This example also uses a MouseMotionListener
 * It uses repaint() and the default version of update().
 * This is the best way.
 * This example illustrates the textbook approved way of doing things. repaint()
 * is preferrred because it is more 'polite' to other applets running in the
 * multitasking environment of a browser.
 * But see the CircleApplet.java  series which discusses difficulties with
 * using repaint().
 *
 * In this version the dot leaves no trace because the
 * default update() paints over in the background colour
 * effectively erasing everything before it calls paint().
 *
 */

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

public class RepaintApplet3a extends Applet {
   int mouseX = -10;
   int mouseY = -10; 

    public void init() {
         addMouseMotionListener(new HandleMouseMotion());
         setBackground(Color.yellow);
    }

    class HandleMouseMotion extends MouseMotionAdapter {
       public void mouseDragged(MouseEvent e) {
          mouseX = e.getX();
          mouseY = e.getY();
          repaint();
       }
    }

/*  // we do not override update, but use the default version
    public void update(Graphics g) {
   paint(g);
    }
*/
    public void paint(Graphics g) {
   g.setColor(Color.red);
   g.fillOval(mouseX-10, mouseY-10, 20, 20);
    }
}