Stella.java
1    /* 
2     * Program that paints a number of concentric squares. 
3     */
4    
5    package npw;
6    
7    
8    import painter.SPainter;
9    import shapes.SSquare;
10   
11   import javax.swing.*;
12   import java.awt.*;
13   import java.util.Random;
14   import java.util.Scanner;
15   
16   
17   public class Stella {
18   
19       //REQUIRED INFRASTRUCTURE
20   
21       public Stella() {
22           paintTheImage();
23       }
24   
25       public static void main(String[] args) {
26           SwingUtilities.invokeLater(new Runnable() {
27               public void run() {
28                   new Stella();
29               }
30           });
31       }
32   
33       // THE PAINTER DOING ITS THING
34   
35       private void paintTheImage() {
36           SPainter painter = new SPainter("Stella", 800, 800);
37           Scanner scanner = new Scanner(System.in);
38           SSquare square = new SSquare(700);
39   
40           String input;
41           int nrOfSquares;
42   
43           input = JOptionPane.showInputDialog("Enter the number of concentric squares:");
44           nrOfSquares = Integer.parseInt(input);
45   
46           Random rand = new Random();
47           float r = rand.nextFloat();
48           float g = rand.nextFloat();
49           float b = rand.nextFloat();
50           Color randomColor1 = new Color(r, g, b);
51           float a = rand.nextFloat();
52           float c = rand.nextFloat();
53           float d = rand.nextFloat();
54           Color randomColor2 = new Color(a, c, d);
55           painter.setColor(randomColor1);
56   
57           int i = 1;
58           while (i<=nrOfSquares) {
59               if (i % 2 == 0) {
60                   painter.setColor(randomColor2);
61                   painter.paint(square);
62                   square.shrink(700/nrOfSquares);
63               } else {
64                   painter.setColor(randomColor1);
65                   painter.paint(square);
66                   square.shrink(700/nrOfSquares);
67               }
68               i = i + 1;
69           }
70   
71   
72       }
73   
74   }
75   
76