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 java.awt.Color; 9 import java.util.Random; 10 import javax.swing.SwingUtilities; 11 import painter.SPainter; 12 import shapes.SCircle; 13 import shapes.SSquare; 14 15 public class Balloons { 16 17 // REQUIRED INFRASTRUCTURE 18 19 public Balloons() { 20 paintTheImage(); 21 } 22 23 public static void main(String[] args) { 24 SwingUtilities.invokeLater(new Runnable() { 25 public void run() { 26 new Balloons(); 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); // ask IntelliJ to generate the stub 36 int nrOfBalloons = 100; 37 paintBalloons(painter,nrOfBalloons); // ask IntelliJ to generate the stub 38 } 39 40 private void paintBalloons(SPainter painter, int nrOfBalloons) { 41 int i = 1; 42 while ( i <= nrOfBalloons ) { 43 paintOneBalloon(painter); // ask IntelliJ to generate the stub 44 i = i + 1; 45 } 46 } 47 48 private void paintOneBalloon(SPainter painter) { 49 Random rgen = new Random(); 50 int rn = rgen.nextInt(3); 51 if ( rn == 0 ) { 52 painter.setColor(Color.RED); 53 } else if (rn == 1 ) { 54 painter.setColor(Color.ORANGE); 55 } else { 56 painter.setColor(Color.YELLOW); 57 } 58 painter.move(); 59 int balloonRadius = 20; 60 SCircle balloon = new SCircle(balloonRadius); 61 painter.paint(balloon); 62 painter.setColor(Color.BLACK); 63 painter.draw(balloon); 64 } 65 66 private void paintSky(SPainter painter) { 67 painter.setColor(Color.BLUE); 68 SSquare sky = new SSquare(2000); 69 painter.paint(sky); 70 } 71 } 72