Alternateballons.java
1    package NPW;
2    
3    import painter.SPainter;
4    import shapes.SCircle;
5    import shapes.SSquare;
6    
7    import javax.swing.*;
8    import java.awt.*;
9    import java.util.Random;
10   
11   public class Alternateballons {
12       public Alternateballons() {
13           paintTheImage();
14       }
15   
16       public static void main(String[] args) {
17           SwingUtilities.invokeLater(new Runnable() {
18               public void run() {
19                   new Alternateballons();
20               }
21           });
22       }
23   
24       private void paintTheImage() {
25           SPainter ya = new SPainter("BALLONS", 600, 600);
26           painySky(ya);
27           int balloncount = 300;
28           paintballons(ya, balloncount);
29       }
30   
31       private void painySky(SPainter ya) {
32           ya.setColor(Color.blue);
33           SSquare sky = new SSquare(2000);
34           ya.paint(sky);
35       }
36   
37       private void paintballons(SPainter ya, int balloncount) {
38           int i = 1;
39           while (i <= balloncount) {
40               paintbal(ya);
41               i = i + 1;
42           }
43       }
44   
45       private void paintbal(SPainter ya) {
46           Random rng = new Random();
47           int rn = rng.nextInt(6);
48           if (rn == 0) {
49               ya.setColor(ua);
50           } else if (rn == 1) {
51               ya.setColor(ukl);
52           } else if (rn == 2) {
53               ya.setColor(ty);
54           } else if (rn == 3) {
55               ya.setColor(ur);
56           } else if (rn == 4) {
57               ya.setColor(h);
58           } else {
59               ya.setColor(t);
60           }
61           ya.move();
62           int balrad = 30;
63           SCircle bal = new SCircle(balrad);
64           ya.paint(bal);
65           ya.setColor(Color.black);
66           ya.draw(bal);
67       }
68       Color ua = new Color(144, 44, 244);
69       Color ukl = new Color(7, 88, 90);
70       Color ty = new Color(25, 38, 190);
71       Color ur = new Color(33, 144, 55);
72       Color h = new Color(177, 77, 77);
73       Color t = new Color(90, 79, 8);
74   
75   
76   }
77