FunSquares.java
1    /* BY:  PRESTON ELIA 
2     * DATE: SEP 22 
3     * DESCRIPTION: 
4     */
5    
6    package npw;
7    
8    import painter.SPainter;
9    import shapes.SSquare;
10   import javax.swing.*;
11   import java.awt.*;
12   
13   public class FunSquares {
14       private void paintTheImage(){
15           SPainter painter = new SPainter("Fun Squares", 600, 600);
16           SSquare square  =  new SSquare(150);
17           paintYellowSquare(painter, square);
18           paintRedSquare(painter, square);
19           paintBlueSquare(painter, square);
20           paintGraySquare(painter, square);
21       }
22   
23       private void paintGraySquare(SPainter painter, SSquare square) {
24           // changes color to GRAY
25           painter.setColor(Color.GRAY);
26           // makes the square bigger
27           square.x2();
28           // moves for gray box 1
29           painter.mbk(150);
30           // paint box 1
31           painter.paint(square);
32           // move for gray box 2
33           painter.mfd(150);
34           painter.mrt(150);
35           // paint box 2
36           painter.paint(square);
37           // move for box 3
38           painter.mlt(300);
39           // paint box 3
40           painter.paint(square);
41           // move to box 4
42           painter.mrt(150);
43           painter.mfd(150);
44           // paint box 4
45           painter.paint(square);
46       }
47   
48   
49       private void paintBlueSquare(SPainter painter, SSquare square) {
50           // changes color to BLUE
51           painter.setColor(Color.BLUE);
52           // move to 1st blue square
53           painter.mrt(150);
54           painter.mbk(150);
55           // paint square
56           painter.paint(square);
57           // move to 2nd square
58           painter.mlt(300);
59           // paint 2nd square
60           painter.paint(square);
61           // move painter back to origin
62           painter.mfd(150);
63           painter.mrt(150);
64       }
65   
66   
67       private void paintRedSquare(SPainter painter, SSquare square) {
68           // changes the painter to color RED
69           painter.setColor(Color.RED);
70           // moves  painter to spot of 1st  RED square
71           painter.mrt(150);
72           painter.mfd(150);
73           // paints first RED square
74           painter.paint(square);
75           // moves to spot of 2nd first square
76           painter.mlt(300);
77           // paints second square
78           painter.paint(square);
79           //moves painter back to origin
80           painter.mrt(300);
81           painter.mbk(150);
82           painter.mlt(150);
83       }
84   
85       private void paintYellowSquare(SPainter painter, SSquare square) {
86           // changes the color to YELLOW
87           painter.setColor(Color.YELLOW);
88           // shrinks square
89           square.s2();
90           // paints the square at origin
91           painter.paint(square);
92       }
93   
94       public FunSquares() {
95           paintTheImage();
96       }
97   
98       public static void main(String[] args) {
99           SwingUtilities.invokeLater(new Runnable() {
100              public void run() {
101                  new FunSquares();
102              }
103          });
104      }
105  }
106