AlternateBalloons.java
1    /* 
2     * Program that paints 100 red, yellow, and orange balloons in a blue sky. 
3     * It will feature commands. 
4     */
5    
6    package npw;
7    
8    import painter.SPainter;
9    import shapes.SCircle;
10   import shapes.SSquare;
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               @Override
26               public void run() {
27                   new AlternateBalloons();
28               }
29           });
30       }
31       // THE PAINTER DOING ITS THING
32       private void paintTheImage() {
33           SPainter painter = new SPainter("Balloons", 6000, 600);
34           paintSky(painter);
35           int nrOfBalloons = 300;
36           paintBalloons(painter, nrOfBalloons);
37       }
38   
39       private void paintBalloons(SPainter painter, int nrOfBalloons) {
40           int i = 1;
41           while (i <= nrOfBalloons ) {
42               paintOneBalloon(painter);
43               i = i + 1;
44           }
45       }
46   
47       private void paintOneBalloon(SPainter painter) {
48           Random rgen = new Random();
49           Color color = new Color(rgen.nextInt(255), rgen.nextInt(255), rgen.nextInt(255));
50           painter.move();
51           int balloonRadius = 30;
52           SCircle balloon = new SCircle(balloonRadius);
53           painter.paint(balloon);
54           painter.setColor(color);
55           painter.paint(balloon);
56           painter.draw(balloon);
57   
58   
59       }
60   
61       private void paintSky(SPainter painter) {
62           painter.setColor(Color.BLUE);
63           SSquare sky = new SSquare(2000);
64           painter.paint(sky);
65       }
66   }
67