1 package npw; 2 import painter.SPainter; 3 import shapes.SRectangle; 4 import java.awt.Color; 5 import javax.swing.SwingUtilities; 6 public class Invention2 { 7 8 private void paintTheImage() { 9 SPainter weeman = new SPainter("Invention 2", 600, 600); 10 SRectangle box = new SRectangle(50, 100); 11 weeman.move(); 12 13 int i = 1; 14 while (i < 5) { 15 if (i == 1) { 16 weeman.setColor(randomColor()); 17 } else if (i==2) { 18 weeman.setColor(randomColor()); 19 }else if (i==3){ 20 weeman.setColor(randomColor()); 21 }else if (i==4) { 22 weeman.setColor(randomColor()); 23 } 24 weeman.paint(box); 25 26 weeman.move(); 27 i=i+1; 28 } 29 } 30 private static Color randomColor() { 31 int rv = (int) (Math.random()*256); 32 int gv = (int) (Math.random()*256); 33 int bv = (int) (Math.random()*256); 34 return new Color(rv,gv,bv); 35 } 36 public Invention2(){ 37 paintTheImage(); 38 } 39 public static void main(String[] args){ 40 SwingUtilities.invokeLater(new Runnable() { 41 public void run() { 42 new Invention2(); 43 }}); 44 } 45 } 46