import java.awt.*; import java.applet.Applet; public class Lines extends Applet { final int MAXLINES = 100; Point starts[] = new Point[MAXLINES]; Point ends[] = new Point[MAXLINES]; Color shades[] = new Color[MAXLINES]; Point anchor = null; Point currpoint; Color currcolor = Color.black; int currline = 0; Font f = new Font("Times", Font.PLAIN, 12); FontMetrics fm = getFontMetrics(f); int clearL, clearR, deleteL, deleteR; public void init() { setBackground(Color.white); repaint(); } public boolean mouseDown(Event evt, int x, int y) { if (y<30) { if (y>10) { if ((x>10) && (x<30)) currcolor = Color.red; else if ((x>40) && (x<60)) currcolor = Color.orange; else if ((x>70) && (x<90)) currcolor = Color.green; else if ((x>100) && (x<120)) currcolor = Color.blue; else if ((x>130) && (x<150)) currcolor = Color.black; else if ((x>clearL) && (xdeleteL) && (x 30)) { if (currline < MAXLINES) addline(x,y); else System.out.println("Ran out of lines"); } anchor = null; return true; } public boolean mouseDrag(Event evt, int x, int y) { if (anchor != null) { currpoint = new Point(x,y); repaint(); } return true; } void addline(int x, int y) { starts[currline] = anchor; ends[currline] = new Point(x,y); shades[currline] = currcolor; currline++; currpoint = null; anchor = null; repaint(); } public void paint( Graphics g ) { g.setColor(Color.red); g.fillRect(10,10,20,20); g.setColor(Color.orange); g.fillRect(40,10,20,20); g.setColor(Color.green); g.fillRect(70,10,20,20); g.setColor(Color.blue); g.fillRect(100,10,20,20); g.setColor(Color.black); g.fillRect(130,10,20,20); g.setFont(f); clearL = 165; clearR = 175+fm.stringWidth("Clear"); g.drawString("Clear",165,25); g.drawRect(160,10,fm.stringWidth("Clear")+10,20); deleteL = clearR+10; deleteR = deleteL+10+fm.stringWidth("Delete"); g.drawString("Delete",clearR+15,25); g.drawRect(clearR+10,10,fm.stringWidth("Delete")+10,20); for (int i=0; i