Invention2.java
1    package npw;
2    
3    import painter.SPainter;
4    import shapes.SCircle;
5    import shapes.SRectangle;
6    import shapes.SSquare;
7    
8    import javax.swing.*;
9    import java.awt.*;
10   import java.util.Random;
11   import java.util.Scanner;
12   
13   public class Invention2 {
14       private void paint() {
15           // Get the input information
16           int number = 70;
17           SPainter painter = new SPainter("Invention2", 800, 800);
18   
19           int i = 700;
20           painter.mfd(10);
21           while (i > 0) {
22   
23               SRectangle Square =  new SRectangle(i,i+20);
24   
25               painter.setColor(random());
26               painter.mbk(5);
27               painter.paint(Square);
28   
29               i = i- (700/number);
30   
31               if (i >300) {
32                   painter.tl();
33                   painter.paint(Square);
34               }
35   
36   
37           }
38   
39   
40   
41   
42   
43       }
44   
45       private static Color random() {
46           Random rgen = new Random();
47           int r = rgen.nextInt(256);
48           int g = rgen.nextInt(256);
49           int b = rgen.nextInt(256);
50           return new Color(r,g,b);
51       }
52   
53       private static Color random2() {
54           Random rgen = new Random();
55           int r = rgen.nextInt(256);
56           int g = rgen.nextInt(256);
57           int b = rgen.nextInt(256);
58           return new Color(r,g,b);
59       }
60   
61   
62       private static int getNumber(String prompt) {
63           String nss = JOptionPane.showInputDialog(null,prompt+"?");
64           Scanner scanner = new Scanner(nss);
65           return scanner.nextInt();
66       }
67   
68       public Invention2() {
69           paint();
70       }
71   
72       public static void main(String[] args) {
73           SwingUtilities.invokeLater(new Runnable() {
74               public void run() {
75                   new Invention2();
76               }
77           });
78       }
79   }
80