Invention1.java
1    /* 
2    * A program that uses a while and if statement to draw the same image each time with one circle and one square object 
3     */
4    
5    package npw;
6    import java.awt.Color;
7    import javax.swing.SwingUtilities;
8    import painter.SPainter;
9    import shapes.SCircle;
10   import shapes.SSquare;
11   
12   public class Invention1 {
13   
14           public Invention1() {
15   
16               paintTheImage();
17           }
18   
19           private void paintTheImage() {
20               SPainter painter = new SPainter("Invention1", 600, 600);
21               SCircle circle = new SCircle(50);
22               SSquare outerSquare= circle.circumscribingSquare();
23               DrawPicture(painter,circle, outerSquare);
24           }
25   
26           private static void DrawPicture(SPainter painter,SCircle circle, SSquare outerSquare) {
27               int x = 0;
28               int y = 0;
29               while (y <= 360){
30                  if (y < 120){
31                       painter.setColor(Color.BLUE);
32                       painter.paint(circle);
33                   } else {
34                      circle.s2();
35                      painter.setColor(Color.PINK);
36                      painter.paint(circle);
37                  }
38                  y = y + 1;
39               }
40   
41               while (x <= 200){
42                   if (x <= 40){
43                       painter.setColor(Color.RED);
44                       painter.draw(outerSquare);
45                       painter.setHeading(x + 2);
46                   } else {
47                       painter.setColor(Color.BLUE);
48                       painter.draw(outerSquare);
49                       painter.setHeading(x);
50                       outerSquare.x2();
51                   }
52                   x = x + 1;
53               }
54           }
55   
56           public static void main(String[] args) {
57               SwingUtilities.invokeLater(new Runnable() {
58               public void run() {
59                   new Invention1();
60                   }
61            });
62           }
63   }
64