/home/sjenks/NetBeansProjects/CS1/src/npw/AlternateBalloons.java
 1 /*
 2  * Program that paints 300 "colorless" balloons in a blue sky.
 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 sjenks
17  */
18 public class AlternateBalloons {
19 
20     //REQUIRED INFRASTRUCTURE
21     Color constr1 = new Color((int) (Math.random()*256),(int) (Math.random()*256),(int) (Math.random()*256));
22     Color constr2 = new Color((int) (Math.random()*256),(int) (Math.random()*256),(int) (Math.random()*256));
23     Color constr3 = new Color((int) (Math.random()*256),(int) (Math.random()*256),(int) (Math.random()*256));
24     Color constr4 = new Color((int) (Math.random()*256),(int) (Math.random()*256),(int) (Math.random()*256));
25     Color constr5 = new Color((int) (Math.random()*256),(int) (Math.random()*256),(int) (Math.random()*256));
26     Color constr6 = new Color((int) (Math.random()*256),(int) (Math.random()*256),(int) (Math.random()*256));
27     
28     public AlternateBalloons(){
29         paintTheImage();
30     }
31     
32     public static void main (String[] args){
33         SwingUtilities.invokeLater(new Runnable(){
34             public void run(){
35                 new AlternateBalloons();
36             }
37         });
38     }
39     
40     //THE PAINTER DOING ITS THING
41     
42     private void paintTheImage(){
43         SPainter painter = new SPainter ("AlternateBalloons", 600,600);
44         paintSky(painter); //ask Netbeams to generate the stub
45         int nrOfBalloons = 300;
46         paintBalloons (painter, nrOfBalloons); //ask Netbeams to generate the stub
47     }
48     
49     private void paintSky(SPainter painter) {
50         painter.setColor(Color.BLUE);
51         SSquare sky = new SSquare(2000);
52         painter.paint(sky);
53     }
54     
55     private void paintBalloons(SPainter painter, int nrOfBalloons){
56         int i = 1;
57         while (i <= nrOfBalloons ){
58             paintOneBalloon (painter); //ask NetBeams to create a stub
59             i = i + 1;
60             
61         }
62     }
63     
64     private void paintOneBalloon (SPainter painter){
65         Random rgen = new Random();
66         int rn = rgen.nextInt(6);
67         if ( rn == 0 ) {
68             painter.setColor(constr1);
69         } else if ( rn == 1 ) {
70             painter.setColor(constr2);
71         } else if (rn == 2) {
72             painter.setColor(constr3);
73         } else if ( rn == 3 ) {
74             painter.setColor(constr4);
75         } else if ( rn == 4 ) {
76             painter.setColor(constr5);
77         } else {
78             painter.setColor(constr6);
79         }
80         
81         painter.move();
82         int balloonRadius = 30;
83         SCircle balloon = new SCircle (balloonRadius);
84         painter.paint (balloon);
85         painter.setColor(Color.BLACK);
86         painter.draw (balloon);
87 
88     }
89 
90     
91 }
92