// Lars Sorensen TYJava in 21 days // excode from pg 222 // // // import java.awt.Graphics; import java.awt.Event; import java.awt.Color; import java.awt.Point; public class Lines extends java.applet.Applet { final int MAXLINES = 100; Point starts[] = new Point[MAXLINES]; // starting points Point ends[] = new Point[MAXLINES]; // ending points Point anchor; // start of current line Point currentpoint; // current end of line int currline = 0; public void init() { setBackground(Color.white); setForeground(Color.blue); } // end of init public boolean mouseDown(Event evt, int x, int y) { anchor = new Point(x,y); return true; } public boolean mouseUp(Event evt, int x, int y) { if ( currline < MAXLINES) addline(x,y); else System.out.println("Too many lines."); return true; } public boolean mouseDrag(Event evt, int x, int y) { currentpoint = new Point(x,y); repaint(); return true; } public boolean keyDown(Event evt, int key) { if ( key == Event.HOME ) { setBackground(Color.white); currline = 0; repaint(); } return true; } void addline(int x, int y) { starts[currline] = anchor; ends[currline] = new Point(x,y); currline++; currentpoint = null; repaint(); } public void paint(Graphics g) { // Draw existing lines for ( int i =0; i < currline; i++ ) g.drawLine(starts[i].x, starts[i].y, ends[i].x, ends[i].y); // draw the current line g.setColor(Color.red); if (currentpoint != null ) g.drawLine(anchor.x, anchor.y, currentpoint.x, currentpoint.y); } // end of paint } // end of class Lines...