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