Stella.java
1    package npw;
2    
3    import painter.SPainter;
4    import shapes.SSquare;
5    
6    import javax.swing.*;
7    import java.awt.*;
8    import java.util.Random;
9    import java.util.Scanner;
10   
11   public class Stella {
12   
13       public Stella() {
14           paintTheImage();
15       }
16   
17       // Every program needs a main method
18       public static void main (String[] args) {
19           SwingUtilities.invokeLater(new Runnable() {
20               public void run() { new Stella(); }
21           });
22       }
23   
24       private void paintTheImage() {
25           // The following code will paint every other square a different color
26           Color odd = randomColor();
27           Color even = randomColor();
28   
29           // User inputs values.
30           String n = JOptionPane.showInputDialog(null,"amount of concentric squares desired");
31           Scanner scanner = new Scanner(n);
32   
33           // create array to configure side lengths
34           int nOfS = scanner.nextInt();
35           double makeSmaller = 700 / nOfS;
36   
37           // Creates tab that image will be displayed in
38           SPainter painter = new SPainter("Stella", 800,800);
39   
40           // Creates square
41           SSquare square = new SSquare(700);
42   
43           // paints the image
44          int i = 1;
45          while (nOfS > 0) {
46              if (i % 2 == 0) {
47                  painter.setColor(even);
48              } else {
49                  painter.setColor(odd);
50              }
51              painter.paint(square);
52              square.shrink(makeSmaller);
53              nOfS = nOfS - 1;
54              i = i + 1;
55          }
56       }
57   
58       private Color randomColor() {
59           Random rgen = new Random();
60           int r = rgen.nextInt(256);
61           int g = rgen.nextInt(256);
62           int b = rgen.nextInt(256);
63           return new Color(r, g, b);
64       }
65   
66   }
67