AlternateBalloons.java
1    /* 
2     * Program that paints 100 red, yellow, orange balloons in a blue sky 
3     * It will feature commands 
4     */
5    package npw;
6    
7    import painter.SPainter;
8    import shapes.SCircle;
9    import shapes.SSquare;
10   
11   import javax.swing.*;
12   import java.awt.*;
13   import java.util.Random;
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 nrOfBallons = 300;
37           paintBalloons(painter,nrOfBallons);
38       }
39   
40       private void paintSky(SPainter painter) {
41           painter.setColor(Color.blue);
42           SSquare sky = new SSquare(2000);
43           painter.paint(sky);
44       }
45   
46       private void paintBalloons(SPainter painter, int nrOfBallons) {
47           int i = 1;
48           Color nameless1 = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
49           Color nameless2 = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
50           Color nameless3 = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
51           Color nameless4 = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
52           Color nameless5 = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
53           Color nameless6 = new Color((int)(Math.random()*256),(int)(Math.random()*256),(int)(Math.random()*256));
54           while(i <= nrOfBallons) {
55               paintOneBalloon(painter, nameless1, nameless2, nameless3, nameless4, nameless5, nameless6);
56               i = i + 1;
57           }
58       }
59   
60       private void paintOneBalloon(SPainter painter, Color nameless1, Color nameless2, Color nameless3,Color nameless4, Color nameless5, Color nameless6) {
61           Random rgen = new Random();
62           int rn = rgen.nextInt(6);
63           if(rn == 0) {
64               painter.setColor(nameless1);
65           } else if(rn == 1) {
66               painter.setColor(nameless2);
67           } else if(rn == 2) {
68               painter.setColor(nameless3);
69           } else if(rn == 3) {
70               painter.setColor(nameless4);
71           } else if(rn == 4) {
72               painter.setColor(nameless5);
73           } else if(rn == 5) {
74               painter.setColor(nameless6);
75           }
76           painter.move();
77           int balloonRadius = 30;
78           SCircle balloon = new SCircle(balloonRadius);
79           painter.paint(balloon);
80           painter.setColor(Color.black);
81           painter.draw(balloon);
82       }
83   }
84