Stella.java
1    /* 
2    * Program to paint  a user-specified number of concentric squares in a 700x700 square with random colors. 
3    */
4    
5    package npw;
6    
7    import java.awt.*;
8    import java.util.Random;
9    import java.util.Scanner;
10   import javax.swing.*;
11   import painter.SPainter;
12   import shapes.SSquare;
13   
14   public class Stella {
15   
16       private void paintTheImage() {
17           String nss = JOptionPane.showInputDialog(null, "number of concentric squares");
18           Scanner scanner = new Scanner(nss);
19           int conSquares = scanner.nextInt();
20           SPainter painter = new SPainter("Stella", 800, 800);
21           double squareSide = 700;
22           SSquare square = new SSquare(squareSide);
23           Random rgen = new Random();
24           int r1 = rgen.nextInt(256);
25           int g1 = rgen.nextInt(256);
26           int b1 = rgen.nextInt(256);
27           int r2 = rgen.nextInt(256);
28           int g2 = rgen.nextInt(256);
29           int b2 = rgen.nextInt(256);
30           painter.setColor(Color.getHSBColor(r1,g1,b1));
31           painter.paint(square);
32           int i = 0;
33           while (i < conSquares) {
34               if (i % 2 == 0) {
35                   painter.setColor(Color.getHSBColor(r2,g2,b2));
36               } else if (i % 2 == 1) {
37                   painter.setColor(Color.getHSBColor(r1,g1,b1));
38               }
39               squareSide = squareSide - (square.side() / conSquares);
40               SSquare newSquare = new SSquare(squareSide);
41               painter.paint(newSquare);
42               i = i + 1;
43           }
44       }
45   
46       public Stella() {
47           paintTheImage();
48       }
49   
50       public static void main(String[] args) {
51           SwingUtilities.invokeLater(new Runnable() {
52               public void run() {
53                   new Stella();
54               }
55           });
56       }
57   }