import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class MouseDrag extends Applet implements MouseMotionListener { private static final long serialVersionUID = 1L; int w, h, s, t; Image buffer; public void init() { addMouseMotionListener(this); w = getSize().width; h = getSize().height; s = w/2; t = h/2; } public void paint(Graphics g) { g.setColor(Color.white); g.fillRect(0, 0, w, h); //clear the screen g.setColor(Color.black); g.drawString("Drag your mouse around.", 10, 30); g.fillOval(s - 10, t - 10, 20, 20); //draw a circle } //end of paint public void update(Graphics g) { if (buffer == null) buffer = createImage(w, h); Graphics g1 = buffer.getGraphics(); paint(g1); g.drawImage(buffer, 0, 0, this); g1.dispose(); } //end of update public void mouseDragged(MouseEvent event) { s = event.getX(); t = event.getY(); repaint(); } //end of mouseDragged public void mouseMoved(MouseEvent event) {} } //end of class MouseDrag