package array; import java.awt.Color; import java.awt.Point; import java.awt.event.MouseEvent; import wheels.users.*; public class MultiArrayShapes 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][3]; 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 MultiArrayShapes () { new RandomMoveButton (270, 400); new BlueingButton (330, 400); new RandomColorButton (390, 400); for (int i = 0, x = marginX; i < shapes.length; i++, x += distance) { int y = marginY; for (int j = 0; j < shapes [i].length; j++, y += distance) { if ((i + j) % 2 == 0) { shapes [i][j] = new Ellipse (x, y); } else { shapes [i][j] = new Rectangle (x, y); } } } } public void colorList () { int i = 0; while (i < shapes.length) { int j = 0; while (j < shapes [i].length) { shapes [i][j].setColor (Color.blue); j++; } i++; } } private void randomColorList () { for (int i = 0; i < shapes.length; i++) { for (int j = 0; j < shapes [i].length; j++) { 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][j].setColor (randomColor); } } } public void randomMoveList () { for (RectangularShape [] shapes_ : shapes) { for (RectangularShape shape : shapes_) { if (Math.random () > 0.8) {break;} if (Math.random () > 0.2) {continue;} int x = shape.getXLocation (); int y = shape.getYLocation () + (int) (10 * Math.random ()); shape.setLocation (x, y); } } } public static void main (String [] arguments) { new MultiArrayShapes (); } }