Stella.java
1    /* 
2     * A program that will paint many squares with the same center point. 
3     */
4    
5    package npw;
6    
7    import painter.SPainter;
8    import java.awt.Color;
9    import java.util.Random;
10   import java.util.Scanner;
11   import shapes.SSquare;
12   import javax.swing.*;
13   
14   public class Stella {
15   
16       public static void main(String[] args){
17   
18           SPainter drake = new SPainter("Stella", 800, 800);
19           int NumberOfSquares = getNumber("Number Of Squares");
20           int i;
21           int ColorNum = 1;
22           SSquare square = new SSquare(700);
23           double SideDifference = 700/NumberOfSquares;
24           Random color = new Random();
25           int r1 = color.nextInt(256);
26           int g1 = color.nextInt(256);
27           int b1 = color.nextInt(256);
28           int r2 = color.nextInt(256);
29           int g2 = color.nextInt(256);
30           int b2 = color.nextInt(256);
31   
32           for( i = 1; i <= NumberOfSquares; i++){
33               if (ColorNum == 1){
34                   drake.setColor(new Color(r1,g1,b1));
35   
36               } else if (ColorNum == 2){
37                   drake.setColor(new Color(r2,g2,b2));
38   
39               }
40   
41               drake.paint(square);
42   
43               if (ColorNum == 1){
44                   ColorNum = 2;
45   
46               } else{
47                   ColorNum = 1;
48   
49               }
50   
51               square = new SSquare(700 - SideDifference * i);
52   
53           }
54       }
55   
56       private static int getNumber(String prompt) {
57           String nss = JOptionPane.showInputDialog(null,prompt+"?");
58           Scanner scanner = new Scanner(nss);
59           return scanner.nextInt();
60   
61       }
62   }
63