Dragging the Mouse
import java.applet.Applet; import java.awt.*; public class Drag extends Applet { private int xValue, yValue; private boolean first; public void init() { first = true; //disables statements in paint initially } public void paint (Graphics g) { if ( !first ) // do not drag the first time g.fillOval (xValue, yValue, 4, 4); } public void update ( Graphics g ) // override Component class update { paint ( g ); // do not clear background; only call paint } public boolean mouseDrag (Event e, int x, int y) { xValue = x; yValue = y; first = false; repaint(); showStatus ( "Event: mouseDrag" ); return true; } }