Invention2.java
1    package npw;
2    
3    import painter.SPainter;
4    import shapes.SRectangle;
5    import java.awt.Color;
6    import javax.swing.SwingUtilities;
7    
8    public class Invention2 {
9    
10       private void paintTheImage() {
11           SPainter drake = new SPainter("Invention2", 750, 700);
12           SRectangle rectangle = new SRectangle(150, 75);
13           drake.move();
14   
15           int i = 1;
16           while (i < 11) {
17               if (i == 1) {
18                   drake.setColor(randomColor());
19               } else if (i==2) {
20                   drake.setColor(Color.PINK);
21               } else if (i==3) {
22                   drake.setColor(randomColor());
23               } else if (i==4) {
24                   drake.setColor(Color.GREEN);
25               } else if (i==5) {
26                   drake.setColor(randomColor());
27               } else if (i==6) {
28                   drake.setColor(Color.YELLOW);
29               } else if (i==7) {
30                   drake.setColor(randomColor());
31               } else if (i==8) {
32                   drake.setColor(Color.BLUE);
33               } else if (i==9) {
34                   drake.setColor(randomColor());
35               } else if (i==10) {
36                   drake.setColor(Color.ORANGE);
37               }
38   
39               drake.paint(rectangle);
40               drake.setColor(Color.BLACK);
41               drake.draw(rectangle);
42               drake.move();
43               i = i + 1;
44   
45           }
46       }
47   
48       private static Color randomColor() {
49           int r = (int)(Math.random()*256);
50           int g = (int)(Math.random()*256);
51           int b = (int)(Math.random()*256);
52           return new Color(r,g,b);
53       }
54   
55       public Invention2() {
56           paintTheImage();
57       }
58       public static void main(String[] args) {
59           SwingUtilities.invokeLater(new Runnable() {
60               public void run() {
61                   new Invention2();
62               }
63           });
64       }
65   
66   }
67   
68