1 /* 2 2 * Program in which (a) the number of concentric squares will be read from a 3 3 * dialog box, (b) two random colors will be chosen, (c) canvas is 800x800 and 4 4 * the largest square is 700x700. 5 5 */ 6 package npw; 7 import painter.SPainter; 8 import shapes.SSquare; 9 10 import java.awt.*; 11 12 public class Stella { 13 14 private static Color randomColor() { 15 int rv = (int) (Math.random() * 256); 16 int gv = (int) (Math.random() * 256); 17 int bv = (int) (Math.random() * 256); 18 return new Color(rv, gv, bv); 19 } 20 21 public static void main(String[] args) { 22 // create the objects to think with 23 SPainter miro = new SPainter("Stella", 800, 800); 24 SSquare square = new SSquare(700); 25 26 int x = 0; 27 boolean color = true; 28 Color color1 = randomColor(); 29 Color color2 = randomColor(); 30 while (x <= 10) { 31 square.shrink(50); 32 if (color == true) { 33 miro.setColor(color1); 34 miro.paint(square); 35 color = false; 36 } else if (color == false) { 37 miro.setColor(color2); 38 miro.paint(square); 39 color = true; 40 } 41 42 x = x + 1; 43 } 44 45 } 46 47 } 48 49