Invention1.java
1    /* 
2     * Invention 1 Uses a while and if statement to draw the same image each time with one circle and one rectangle object 
3     */
4    
5    
6    package npw;
7    import java.awt.Color;
8    import javax.swing.SwingUtilities;
9    import painter.SPainter;
10   import shapes.SCircle;
11   
12   import shapes.SSquare;
13   public class Invention1 {
14       // REQUIRED INFRASTRUCTURE
15       public Invention1() {
16           paintTheImage();
17       }
18   
19   
20   
21       private void paintTheImage() {
22           SPainter painter = new SPainter("Invention1", 600, 600);
23           paintBackground(painter);
24           int nrOfRect = 6;
25           SCircle Circle = new SCircle(180);
26           DrawPicture(painter,Circle);
27           paintRectangles(painter, nrOfRect);
28   
29   
30       }
31   
32       private static void DrawPicture(SPainter painter,SCircle Circle) {
33           int j = 0;
34           while (j < 5) {
35               if (Circle.radius() > 120) {
36                   painter.setColor(Color.WHITE);
37               } else if (Circle.radius() == 120) {
38                   painter.setColor(Color.BLACK);
39               } else painter.setColor(Color.YELLOW);
40               painter.paint(Circle);
41               Circle.shrink(30);
42               j = j+1;
43           }
44       }
45   
46       private void paintBackground(SPainter painter) {
47           painter.setColor(Color.BLACK);
48           SSquare back = new SSquare(2000);
49           painter.paint(back);
50       }
51   
52       private void paintRectangles(SPainter painter, int nrOfRect) {
53   
54           int i = 1;
55           while (i <= nrOfRect) {
56               paintPicture(painter);
57               i = i + 1;
58           }
59       }
60   
61   
62   
63   
64       private void paintPicture(SPainter painter) {
65   
66   
67           int side = 87;
68           SSquare square = new SSquare(side);
69           painter.mfd(square.side());
70           painter.tr();
71           painter.tr();
72           painter.setColor(Color.WHITE);
73           painter.paint(square);
74       }
75       public static void main(String[] args) {
76           SwingUtilities.invokeLater(new Runnable() {
77               public void run() {
78                   new Invention1();
79               }
80           });
81       }
82   }
83   
84