//******************************************************************** // LineUp.java Author: Lewis and Loftus // // Demonstrates the use of a graphical object. //******************************************************************** import StickFigure1; import java.applet.Applet; import java.awt.*; public class LineUp1 extends Applet { private final int APPLET_WIDTH = 400; private final int APPLET_HEIGHT = 150; private final int HEIGHT_MIN = 100; private final int VARIANCE = 30; private StickFigure1 figure1, figure2, figure3, figure4; //----------------------------------------------------------------- // Creates several stick figures with varying characteristics. //----------------------------------------------------------------- public void init () { int h1, h2, h3, h4; // heights of stick figures h1 = (int) (Math.random() * VARIANCE) + HEIGHT_MIN; h2 = (int) (Math.random() * VARIANCE) + HEIGHT_MIN; h3 = (int) (Math.random() * VARIANCE) + HEIGHT_MIN; h4 = (int) (Math.random() * VARIANCE) + HEIGHT_MIN; int r1 = (int) (Math.random() * 256); int r2 = (int) (Math.random() * 256); int r3 = (int) (Math.random() * 256); int r4 = (int) (Math.random() * 256); int g1 = (int) (Math.random() * 256); int g2 = (int) (Math.random() * 256); int g3 = (int) (Math.random() * 256); int g4 = (int) (Math.random() * 256); int b1 = (int) (Math.random() * 256); int b2 = (int) (Math.random() * 256); int b3 = (int) (Math.random() * 256); int b4 = (int) (Math.random() * 256); Color color1= new Color(r1,g1,b1); Color color2= new Color(r2,g2,b2); Color color3= new Color(r3,g3,b3); Color color4= new Color(r4,g4,b4); figure1 = new StickFigure1 (100, 150, color1, h1); figure2 = new StickFigure1 (150, 150, color2, h2); figure3 = new StickFigure1 (200, 150, color3, h3); figure4 = new StickFigure1 (250, 150, color4, h4); setBackground (Color.gray); setSize (APPLET_WIDTH, APPLET_HEIGHT); } //----------------------------------------------------------------- // Paints the stick figures on the applet. //----------------------------------------------------------------- public void paint (Graphics page) { figure1.draw (page); figure2.draw (page); figure3.draw (page); figure4.draw (page); } }