/home/cdesrivi/NetBeansProjects/CS1/src/npw/AlternativeBalloons.java
 1 /*
 2  * Program that paints 100 red, yellow and orange AlternativeBalloons in a blue sky.
 3  * It will feature commands.
 4  */
 5 
 6 package npw;
 7 
 8 import java.awt.Color;
 9 import java.util.Random;
10 import javax.swing.SwingUtilities;
11 import painter.SPainter;
12 import shapes.SCircle;
13 import shapes.SSquare;
14 
15 /**
16  *
17  * @author cdesrivi
18  */
19 public class AlternativeBalloons {
20 
21     // REQUIRED INFRASTRUCTURE
22     
23     public AlternativeBalloons() {
24         paintTheImage();
25     }
26     
27     public static void main(String[] args) {
28         SwingUtilities.invokeLater(new Runnable() {
29             public void run() {
30                 new AlternativeBalloons();
31             }
32         });
33     }
34 
35     // THE PAINTER DOING ITS THING
36     
37     private void paintTheImage() {
38         SPainter painter = new SPainter("AlternativeBalloons", 600, 600);
39         paintSky(painter); // ask Netbeans to generate the stub
40         int nrOfAlternativeBalloons = 300;
41         paintAlternativeBalloons(painter,nrOfAlternativeBalloons); // ask Netbeans to generate the stub
42         painter.setRandomColor();
43     }
44     
45     private void paintSky(SPainter painter) {
46         painter.setColor(Color.BLUE);
47         SSquare sky = new SSquare(2000);
48         painter.paint(sky);
49     }
50     
51     private void paintAlternativeBalloons(SPainter painter, int nrOfAlternativeBalloons) {
52         int i = 1;
53         while ( i <= nrOfAlternativeBalloons) {
54             paintOneBalloon(painter); //ask Netbeans to generate the stub
55             i = i + 1;
56         }
57     }
58 
59     private void paintOneBalloon(SPainter painter) {
60         Random rgen = new Random();
61         int rn = rgen.nextInt(3);
62         if ( rn == 0 ) {
63             painter.setColor(Color.RED);
64         } else if  ( rn == 1) {
65             painter.setColor(Color.ORANGE);
66         } else if  ( rn == 2) {
67             painter.setRandomColor();
68         } else {
69             painter.setColor(Color.YELLOW);
70         }
71         painter.move();
72         int balloonRadius = 30;
73         SCircle balloon = new SCircle(balloonRadius);
74         painter.paint(balloon);
75         painter.setRandomColor();
76         painter.draw(balloon);
77     }
78 
79 }
80