package list; import java.awt.Color; import java.awt.Point; import java.awt.event.MouseEvent; import wheels.users.*; public class List extends Frame { private static final int marginX = 100; private static final int marginY = 100; private static final int distance = 60; public class Node { private RectangularShape shape; private Node next; public Node (RectangularShape shape, Node list) { this.shape = shape; this.next = list; } } 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 (); } } private Node list; /** Creates and starts a new List application. */ public List () { new RandomMoveButton (270, 400); new BlueingButton (330, 400); new RandomColorButton (390, 400); int y = marginY; for (int i = 0, x = marginX; i < 8; i++, x += distance) { RectangularShape shape; if (i % 2 == 0) { shape = new Ellipse (x, y); } else { shape = new Rectangle (x, y); } Node node = new Node (shape, list); list = node; } } public void colorList () { Node node = list; while (node != null) { node.shape.setColor (Color.blue); node = node.next; } } private void randomColorList () { for (Node node = list; node != null; node = node.next) { 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); node.shape.setColor (randomColor); } } public void randomMoveList () { for (Node node = list; node != null; node = node.next) { if (Math.random () > 0.8) {break;} if (Math.random () > 0.2) {continue;} int x = node.shape.getXLocation (); int y = node.shape.getYLocation () + (int) (10 * Math.random ()); node.shape.setLocation (x, y); } } public static void main (String [] arguments) { new List (); } }