1 /* 2 * A program where a integer between 0 and 120 is randomly generated. 3 * The lower the number the higher the rectangles will stack. 4 */ 5 6 package npw; 7 8 import java.util.Random; 9 import java.awt.Color; 10 import javax.swing.SwingUtilities; 11 import painter.SPainter; 12 import shapes.SRectangle; 13 14 public class Invention2 { 15 16 private void paintTheImage() { 17 SPainter painter = new SPainter("Image", 800, 800); 18 SRectangle rectangle = new SRectangle(40, 20); 19 painter.setColor(Color.BLUE); 20 painter.mbk(360); 21 int r = randomInteger(); 22 if (r > 100) { 23 painter.draw(rectangle); 24 } else { 25 while (r < 100) { 26 painter.draw(rectangle); 27 painter.mfd(40); 28 r = r + 5; 29 } 30 } 31 } 32 33 private static int randomInteger() { 34 Random rgen = new Random(); 35 int r = rgen.nextInt(120); 36 return r; 37 } 38 39 public Invention2(){ 40 paintTheImage(); 41 } 42 43 public static void main(String[] args){ 44 SwingUtilities.invokeLater(new Runnable() { 45 @Override 46 public void run() { 47 new Invention2(); 48 } 49 }); 50 } 51 } 52