/* **************************************************************************** * Kelli Wiseth * kelli@alameda-tech-lab.com * CIS 255AX * Program name: ShapeTest.java * Program Description: A driver applet that creates three arrays of different * shapes that comprise an inheritance class hierarchy that starts with * MyLine (MyLine is the superclass, MyTriangle and MyCircle each extend * MyLine.) Math.random is used to generate random starting values for * these shapes, as well as random colors. The shifting values and scaling * factors applied to Math.random() are arbitrary, based on * trial-and-error experimentation. * * Assignment #4 * 29 March 2005 **************************************************************************** */ import java.awt.*; import javax.swing.*; public class ShapeTest extends JApplet { private MyLine line[] = new MyLine[4]; private MyTriangle triangle[] = new MyTriangle[4]; private MyCircle circle[] = new MyCircle[4]; public void init() { String output = "Programmed by Kelli Wiseth\n"; for (int ctr = 0; ctr < 4; ctr++) { //Generating some random data to be used for creating the arrays of //objects (MyLine, MyTriangle, MyCircle) int myX = (1 + (int)(Math.random() * 100)); int myY = (5 + (int)(Math.random() * 120)); double myRadius = (1 + (int)(Math.random() * 130)); line[ctr] = new MyLine(myX, myY, myX+250, myY+250); triangle[ctr] = new MyTriangle(myX+75, myY+100, myX+50, myY+175, myX+100, myY+125); circle[ctr] = new MyCircle(myX+75, myY+100, myRadius); } } // end method init public void paint(Graphics g) { super.paint(g); for (int ctr=0; ctr < line.length; ctr++) { //generate random RGB (red-green-blue) values for colors g.setColor( new Color ((1 + ( int ) ( Math.random() * 255 )), (1 + ( int ) ( Math.random() * 255 )), ((1 + ( int ) ( Math.random() * 255))))); line[ctr].draw(g); triangle [ctr].draw(g); circle[ctr].draw(g); } showStatus("Programmed by Kelli Wiseth [ShapeTest.java]"); } // end method paint } // end class ShapeTest