Invention1.java
1    /* 
2     * Paints an image to the following constraints: at least one (while) statement, 
3     * at least one (if) statement, features both circles and squares, all created 
4     * from one circle and one square, creates the same image everytime. 
5     */
6    package npw;
7    
8    import painter.SPainter;
9    import shapes.SCircle;
10   import shapes.SSquare;
11   
12   import javax.swing.*;
13   import java.awt.*;
14   
15   
16   public class Invention1 {
17   
18   
19        public static void main(String[] args) {
20            // CREATE OBJECTS TO THINK WITH
21            SPainter miro = new SPainter("Invention1", 600, 600);
22            SSquare square = new SSquare(50);
23            SCircle circle = new SCircle(30);
24   
25            miro.setColor(Color.ORANGE);
26            square.expand(50);
27            miro.paint(square);
28            square.shrink(50);
29   
30            miro.mrt(square.side());
31            miro.setColor(Color.GREEN);
32            miro.paint(circle);
33            miro.mlt(square.side());
34   
35            //GRAB THE INPUT INFORMATION
36            while (true) {
37                square.expand(50);
38                Color colorOfSquare = changeColor();
39                miro.setColor(colorOfSquare);
40                miro.paint(square);
41                square.shrink(50);
42                miro.mrt(square.side());
43                miro.setColor(Color.GREEN);
44                miro.paint(circle);
45                miro.mlt(square.side());
46   
47            }
48   
49        }
50   
51        private static Color changeColor() {
52            String color = JOptionPane.showInputDialog(null, "Change the color of the box?");
53            if (color.equalsIgnoreCase("orange")) {
54                return Color.ORANGE;
55            } else if (color.equalsIgnoreCase("green")) {
56               return Color.GREEN;
57            } else if (color.equalsIgnoreCase("blue")) {
58                return Color.BLUE;
59            } else {
60                return Color.BLACK;
61            }
62        }
63   
64   }
65   
66