1 package npw; 2 import java.awt.Color; 3 import java.util.Random; 4 import javax.swing.SwingUtilities; 5 6 import painter.SPainter; 7 import shapes.SRectangle; 8 9 10 public class Invention2 { 11 public Invention2() { 12 paintTheImage(); 13 } 14 15 public static void main(String[] args) { 16 SwingUtilities.invokeLater(new Runnable() { 17 public void run() { 18 new Invention2(); 19 20 } 21 }); 22 } 23 private void paintTheImage(){ 24 SPainter painter= new SPainter("Invention 2",600,600); 25 int nrOfRectangles= 30; 26 paintRectangles(painter,nrOfRectangles); 27 } 28 private void paintRectangles(SPainter painter, int nrOfRectangles){ 29 int i=1; 30 while (i<=nrOfRectangles){ 31 paintOneRectangle(painter, i); 32 i= i+1; 33 } 34 } 35 private void paintOneRectangle(SPainter painter, int i){ 36 SRectangle rectangle= new SRectangle(50,50); 37 if(i > 20) { 38 painter.setColor(Color.RED); 39 } else if(i>10) { 40 painter.setColor(Color.GRAY); 41 }else if(i < 10) { 42 painter.setColor(Color.BLUE); 43 } 44 painter.move(); 45 painter.paint(rectangle); 46 painter.setColor(Color.BLACK); 47 painter.draw(rectangle); 48 } 49 50 } 51