Stella.java
1    /* 
2     * A program to paint a given number of concentric squares. 
3     */
4    
5    package npw;
6    
7    import painter.SPainter;
8    import shapes.SSquare;
9    import java.awt.Color;
10   import javax.swing.*;
11   import java.util.Scanner;
12   
13   public class Stella {
14       private void paintTheImage() {
15           int number = getNumber("What is the number of concentric squares would you like");
16           int shrink = 700 / number;
17           SPainter lloyd = new SPainter("Stella", 800, 800);
18           SSquare petion = new SSquare(700);
19           Color one = randomColor();
20           Color two = randomColor();
21   
22           int i = 0;
23           while (i < number) {
24               if (i % 2 == 0) {
25                   lloyd.setColor(one);
26               } else {
27                   lloyd.setColor(two);
28               }
29               lloyd.paint(petion);
30               petion.resetSide((int) (petion.side() - shrink));
31               i = i + 1;
32           }
33       }
34   
35       private static int getNumber(String prompt) {
36           String kate = JOptionPane.showInputDialog(null, prompt + "?");
37           Scanner tom = new Scanner(kate);
38           return tom.nextInt();
39       }
40   
41       private static Color randomColor() {
42           int rv = (int) (Math.random() * 256);
43           int gv = (int) (Math.random() * 256);
44           int bv = (int) (Math.random() * 256);
45           return new Color(rv, gv, bv);
46       }
47   
48       public Stella() {
49           paintTheImage();
50       }
51   
52       public static void main(String[] args) {
53           SwingUtilities.invokeLater(new Runnable() {
54               public void run() {
55                   new Stella();
56               }
57           });
58       }
59   }
60   
61   
62