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 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 @Override 26 public void run() { 27 new Balloons(); 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 = 100; 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 int rn = rgen.nextInt(3); 50 if ( rn == 0 ) { 51 painter.setColor(Color.RED); 52 } else if (rn == 1 ) { 53 painter.setColor(Color.ORANGE); 54 } else { 55 painter.setColor(Color.YELLOW); 56 } 57 painter.move(); 58 int balloonRadius = 20; 59 SCircle balloon = new SCircle(balloonRadius); 60 painter.paint(balloon); 61 painter.setColor(Color.BLACK); 62 painter.draw(balloon); 63 } 64 65 private void paintSky(SPainter painter) { 66 painter.setColor(Color.BLUE); 67 SSquare sky = new SSquare(2000); 68 painter.paint(sky); 69 } 70 } 71