import awt.*; import browser.Applet; class SketchApplet extends Applet { int points[][] = new int[1024][4]; int point1_x,point1_y,point2_x,point2_y,Number_of_Lines; int x1,y1,w,h,dx,dy,sx,sy; Graphics graphics; Thread kicker = null; public void init() { Number_of_Lines=0; resize(600,300); } public void start() { point1_x = 0; point1_y = 0; point2_x = 0; point2_y = 0; } public void stop() { kicker = null; } public void paint(Graphics g) { g.drawRect(1,1,300,300); g.setForeground(Color.red); g.fillRect(0, 0, 300, 300); g.setForeground(Color.blue); g.fillRect(375,233,180,67); g.setForeground(Color.yellow); g.fillRect(325,0,300,225); g.setForeground(Color.red); g.drawString("H O W T O P L A Y", 380,25); g.drawString("*", 339,75); g.drawString("*", 339,115); g.drawString("*", 339,195); g.setForeground(Color.blue); g.drawString("--------------", 380,35); g.setForeground(Color.menuFore); g.drawString("MOVE YOUR MOUSE INSIDE THE RED", 345,75); g.drawString("SQUARE.", 345,95); g.drawString("PUSHING ON THE MOUSE START", 345,115); g.drawString("MOVING THE MOUSE IN THE", 345,135); g.drawString("DIRECTION YOU WANT TO DRAW", 345,155); g.drawString("THE LINES.", 345,175); g.drawString("LOOK IN THE BLUE SQUARE AND.", 345,195); g.drawString("SEE HOW MANY LINES YOU DREW.", 345,215); g.setForeground(Color.white); g.drawRect(5,5,292,292); g.setForeground(Color.white); g.drawRect(5,5,292,292); g.setForeground(Color.white); g.drawRect(5,5,292,292); g.setForeground(Color.white); g.drawRect(1,1,292,292); g.setForeground(Color.white); g.drawRect(1,1,292,292); g.setForeground(Color.white); g.drawRect(1,1,292,292); g.setForeground(Color.white); g.drawRect(1,1,293,293); g.setForeground(Color.white); g.drawRect(1,1,293,293); g.setForeground(Color.white); g.drawRect(1,1,293,293); g.setForeground(Color.white); g.drawRect(3,3,294,294);g.setForeground(Color.white); g.drawRect(1,1,291,291); g.setForeground(Color.white); g.drawRect(1,1,297,297); g.setForeground(Color.white); g.drawRect(1,1,297,297); g.setForeground(Color.white); g.drawRect(1,1,297,297); g.setForeground(Color.white); g.drawRect(1,1,298,298); g.setForeground(Color.white); g.drawRect(1,1,298,298); g.setForeground(Color.white); g.drawRect(1,1,298,298); g.setForeground(Color.white); g.drawRect(5,5,297,297); g.setForeground(Color.white); g.drawRect(5,5,297,297); g.setForeground(Color.white); g.drawRect(5,5,297,297); g.setForeground(Color.white); g.drawString("Number_of_Lines =" + Number_of_Lines, 400, 265); for(int i=0; i<=Number_of_Lines; i++) { g.setForeground(Color.yellow); g.drawLine(points[i][0],points[i][1],points[i][2],points[i][3]); } } public void update(Graphics g) { g.clipRect(x1,y1,w,h); paint(g); } public void mouseDown(int x, int y) { Number_of_Lines++; sx = x; sy = y; points[Number_of_Lines][0] = x; points[Number_of_Lines][1] = y; points[Number_of_Lines][2] = x; points[Number_of_Lines][3] = y; } public void mouseDrag(int x, int y) { int tmp; points[Number_of_Lines][2] = x; points[Number_of_Lines][3] = y; if(Math.abs(sx-x) > Math.abs(sx-dx)) dx = x; if(Math.abs(sy-y) > Math.abs(sy-dy)) dy = y; x1 = Math.min(sx,dx); y1 = Math.min(sy,dy); w = Math.abs(sx-dx); h = Math.abs(sy-dy); repaint(); } public void mouseUp(int x, int y) { points[Number_of_Lines][2] = x; points[Number_of_Lines][3] = y; repaint(); } }