/home/mbilodea/NetBeansProjects/CS1/src/npw/AlternateBalloons.java
 1 /*
 2  * Porgram that paints 300 balloons of six random colors.
 3  * It will feature commands.
 4  */
 5 package npw;
 6 
 7 import java.awt.Color;
 8 import java.util.Random;
 9 import javax.swing.SwingUtilities;
10 import painter.SPainter;
11 import shapes.SCircle;
12 import shapes.SSquare;
13 
14 /**
15  *
16  * @author mbilodea
17  */
18 public class AlternateBalloons {
19 
20     // REQUIRED INFRASTRUCTURE
21     
22     public AlternateBalloons() {
23         paintTheImage();
24     }
25     
26     public static void main(String[] args) {
27         SwingUtilities.invokeLater(new Runnable() {
28             public void run() {
29                 new AlternateBalloons();
30             }
31         });
32     }
33     
34     // THE PAINTER DOING ITS THING
35 
36     private void paintTheImage() {
37         SPainter painter = new SPainter("Balloons", 600, 600);
38         paintSky(painter);
39         int nrOfBalloons = 300;
40         paintBalloons(painter,nrOfBalloons);
41     }
42 
43     private void paintSky(SPainter painter) {
44         painter.setColor(Color.BLUE);
45         SSquare sky = new SSquare(2000);
46         painter.paint(sky);
47     }
48 
49     private void paintBalloons(SPainter painter, int nrOfBalloons) {
50         int i = 1;
51         while ( i <= nrOfBalloons ) {
52             paintOneBalloon(painter);
53             i = i + 1;
54         }
55     }
56     
57     private void paintOneBalloon(SPainter painter) {
58         Random rgen = new Random();
59         Color color1 = new Color(43, 75, 25);
60         Color color2 = new Color(153, 152, 80);
61         Color color3 = new Color(122, 36, 234);
62         Color color4 = new Color(138, 198, 200);
63         Color color5 = new Color(78, 32, 167);
64         Color color6 = new Color(53, 254, 20);
65         int rn = rgen.nextInt(5);
66         if ( rn == 0 ) {
67             painter.setColor(color1);
68         } else if ( rn == 1 ) {
69             painter.setColor(color2);
70         } else if ( rn == 2 ) {
71             painter.setColor(color3);
72         } else if ( rn == 3 ) {
73             painter.setColor(color4);
74         } else if ( rn == 4 ) {
75             painter.setColor(color5);
76         } else if ( rn == 5 ) {
77             painter.setColor(color6);
78         }
79         painter.move();
80         int balloonRadius = 30;
81         SCircle balloon = new SCircle(balloonRadius);
82         painter.paint(balloon);
83         painter.setColor(Color.BLACK);
84         painter.draw(balloon);
85     }
86 }