Stella.java
1    /* 
2    The number of concentric squares will be read from a dialog box. 
3    Two randomly chosen colors will be used for the image that is painted when the program is run. 
4    The canvas will be of size 800 by 800 and the largest square will be 700 by 700. 
5     */
6    package NPW;
7    
8    import java.awt.*;
9    import java.util.Random;
10   import java.util.Scanner;
11   import javax.swing.*;
12   
13   import painter.SPainter;
14   import shapes.SCircle;
15   import shapes.SRectangle;
16   import shapes.SSquare;
17   
18   public class Stella {
19   
20       private void paintTheImage() {
21   
22           int nrOfSquares = getNumber("How many concentric squares");
23           int sideLength = 700;
24   
25           //Establish painter
26           int shrink = sideLength/nrOfSquares;
27           SPainter painter = new SPainter("Stella", 800,800);
28           painter.setBrushWidth(4);
29           SSquare square = new SSquare(sideLength);
30           painter.setRandomColor();
31           Color color1 = painter.color;
32           painter.setRandomColor();
33           Color color2 = painter.color;
34           painter.paint(square);
35   
36           paintStella(painter,nrOfSquares,square,shrink,color1,color2);
37   
38   
39       }
40   
41       private static int getNumber(String prompt) {
42           String nss = JOptionPane.showInputDialog(null,prompt+"?");
43           Scanner scanner = new Scanner(nss);
44           return scanner.nextInt();
45       }
46   
47       private static void paintStella(SPainter painter,int nrOfSquares, SSquare square, int
48                                       shrink,Color color1, Color color2) {
49           int i = 1;
50           while (i <= nrOfSquares/2) {
51               square.shrink(shrink);
52               painter.setColor(color1);
53               painter.paint(square);
54               square.shrink(shrink);
55               painter.setColor(color2);
56               painter.paint(square);
57               i = i + 1;
58   
59           }
60   
61       }
62   
63       public Stella() {paintTheImage();}
64   
65       public static void main(String[] args){
66           SwingUtilities.invokeLater(new Runnable() {
67               @Override
68               public void run() {
69                   new Stella();
70               }
71           });
72       }
73   }
74