//SampleApplet.java //Robert J. Russell import java.awt.*; import java.applet.*; public class SampleApplet extends Applet { /* To try this out yourself, create an applet, calling the project whatever * you want. Then erase the paint() method in your applet. Finally copy and * paste the sleep() and paint() methods below into your project (below its * init() method. Compile and run! */ public void init() { } public void sleep(int ms) { try { Thread.sleep(ms); } catch (Exception e) { } } public void paint(Graphics g) { g.drawString("Some Sample Graphics", 100, 20 ); g.drawString("This program will draw a rectangle three ways", 80, 40 ); g.drawString("The four vertices will be: (100,150), (200,150)",60, 60 ); g.drawString(" and: (100,190), (200,190)", 20, 80 ); g.drawString("First, we use the drawRect() method:",80, 120 ); //The first two parameters are the upper left hand vertex (100,.150) //The third parameter, 100, is the width of the rectangle //The last parameter, 40, is the height of the rectangle g.drawRect(100,150,100,40); sleep(2000); //now erase the rectangle and the message by using white as the color g.setColor(Color.white); g.drawString("First, we use the drawRect() method:",80, 120 ); g.drawRect(100,150,100,40); //change the color to blue g.setColor(Color.blue); g.drawString("Now we will draw four separate lines:",80, 120 ); g.drawLine(100,150,200,150); sleep(400); g.drawLine(200,150,200,190); sleep(400); g.drawLine(200,190,100,190); sleep(400); g.drawLine(100,190,100,150); sleep(2000); //now erase the rectangle and the message by using white as the color g.setColor(Color.white); g.drawString("Now we will draw four separate lines:",80, 120 ); g.drawRect(100,150,100,40); //change the color to red g.setColor(Color.red); g.drawString("Now we will use the drawPolygon() method:",80, 120 ); int[] x = {100,200,200,100}; int[] y = {150,150,190,190}; g.drawPolygon(x, y, 4); sleep(2000); //Print final message g.setColor(Color.black); g.drawString("Wasn't that fun?", 80,240); } }