1 package npw; 2 import java.awt.Color; 3 import java.util.Random; 4 import painter.SPainter; 5 import shapes.SRectangle; 6 import shapes.SSquare; 7 public class Invention2 8 { 9 public static void main(String[] args) 10 { 11 SPainter paint = new SPainter ("Invention 2", 600, 600); 12 paintBackground(paint); 13 paintRectangle(paint, 20,100); 14 } 15 private static void paintBackground(SPainter paint) 16 { 17 paint.setColor(Color.YELLOW); 18 SSquare background = new SSquare(2000); 19 paint.paint(background); 20 } 21 private static void paintRectangle(SPainter painter, int w, int h) 22 { 23 int i = 1; 24 while (i<=w) 25 { 26 while (i<=h) 27 paintOneRectangle(painter); 28 i = i + 1; 29 } 30 } 31 private static Color randomColor() 32 { 33 Random a = new Random(); 34 int r = a.nextInt(256); 35 int g = a.nextInt(256); 36 int b = a.nextInt(256); 37 return new Color(r,b,g); 38 } 39 private static void paintOneRectangle(SPainter paint) 40 { 41 Random a = new Random(); 42 int b = a.nextInt(3); 43 if ( b == 0) { 44 paint.setColor(randomColor()); 45 } else if (b == 1) { 46 paint.setColor(randomColor()); 47 } else if (b ==2) { 48 paint.setColor(randomColor()); 49 } 50 paint.move(); 51 SRectangle rectangle = new SRectangle(100,20); 52 paint.paint(rectangle); 53 paint.setColor(Color.BLUE); 54 paint.draw(rectangle); 55 } 56 } 57 58 59 60 61