Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 7.3</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0><TR><TD> <APPLET CODEBASE="classes" CODE="Applet3.class" WIDTH=500 HEIGHT=100> </APPLET> </TD></TR></TABLE> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.*; public class Applet3 extends Applet { Point startPt; Point endPt; public void init() { setBackground(Color.white); } public boolean mouseDown(Event evt, int x, int y) { startPt = new Point(x, y); return true; } public boolean mouseDrag(Event evt, int x, int y) { Graphics g = getGraphics(); endPt = new Point(x, y); g.drawLine(startPt.x, startPt.y, endPt.x, endPt.y); startPt = endPt; return true; } }