public Java0620 extends Applet { public void paint(Graphics g) { Polygon penta = new Polygon(); penta.addPoint(300,350); penta.addPoint(250,200); penta.addPoint(550,200); penta.addPoint(500,350); g.drawPolygon(penta); } } Figure 6.27 Continued 6.7 Random Graphics Objects There are two Java concepts you have learned that combine very nicely. You have learned to create a variety of graphic images with methods of the Graphics and Color classes. In this chapter you have also learned how to generate random numbers of a specific range. When you combine these two features, you can create some interesting programs. Program in figure 6.18, generates random lines. These lines are Java0621.java, all colored black. The program is meant for an applet window that is 800 by 600 pixels in size. You will see that the random numbers generate integers in the entire range of the applet window. Figure 6.28 // Java0621.java // This program displays 1000 random import java.awt.*; import java.applet.*; import java.util.Random;
public Java0620 extends Applet { public void paint(Graphics g) { Polygon penta = new Polygon(); penta.addPoint(300,350); penta.addPoint(250,200); penta.addPoint(550,200); penta.addPoint(500,350); g.drawPolygon(penta); } } Figure 6.27 Continued 6.7 Random Graphics Objects There are two Java concepts you have learned that combine very nicely. You have learned to create a variety of graphic images with methods of the Graphics and Color classes. In this chapter you have also learned how to generate random numbers of a specific range. When you combine these two features, you can create some interesting programs. Program Java0621.java, in figure 6.18, generates random lines. These lines are all colored black. The program is meant for an applet window that is 800 by 600 pixels in size. You will see that the random numbers generate integers in the entire range of the applet window. Figure 6.28 // Java0621.java // This program displays 1000 random import java.awt.*; import java.applet.*; import java.util.Random;
Text06-UsingObjectMethods-1.docx