package array; import java.awt.Color; import java.awt.Point; import java.awt.event.MouseEvent; import wheels.users.*; public class ArrayShapes extends Frame { private static final int marginX = 100; private static final int marginY = 100; private static final int distance = 60; private RectangularShape [] shapes = new RectangularShape [8]; public class BlueingButton extends RoundedRectangle { public BlueingButton (int x, int y) { super (x, y); } public void mouseReleased (MouseEvent event) { colorList (); } } public class RandomColorButton extends RoundedRectangle { public RandomColorButton (int x, int y) { super (x, y); } public void mouseReleased (MouseEvent event) { randomColorList (); } } public class RandomMoveButton extends RoundedRectangle { public RandomMoveButton (int x, int y) { super (x, y); } public void mouseReleased (MouseEvent event) { randomMoveList (); } } /** Creates and starts a new List application. */ public ArrayShapes () { new RandomMoveButton (270, 400); new BlueingButton (330, 400); new RandomColorButton (390, 400); int y = marginY; for (int i = 0, x = marginX; i < shapes.length; i++, x += distance) { if (i % 2 == 0) { shapes [i] = new Ellipse (x, y); } else { shapes [i] = new Rectangle (x, y); } } } public void colorList () { int i = 0; while (i < shapes.length) { shapes [i].setColor (Color.blue); i++; } } private void randomColorList () { for (int i = 0; i < shapes.length; i++) { int red = (int) (256 * Math.random ()); int green = (int) (256 * Math.random ()); int blue = (int) (256 * Math.random ()); Color randomColor = new Color (red, green, blue); shapes [i].setColor (randomColor); } } public void randomMoveList () { for (int i = 0; i < shapes.length; i++) { if (Math.random () > 0.8) {break;} if (Math.random () > 0.2) {continue;} int x = shapes [i].getXLocation (); int y = shapes [i].getYLocation () + (int) (10 * Math.random ()); shapes [i].setLocation (x, y); } } public static void main (String [] arguments) { new ArrayShapes (); } }