Invention1.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.Scanner;
10   
11   public class Invention1 {
12   
13       private void paintTheImage() {
14           int nrOfSquares = getNumber("Number of Squares ");
15           String color = getColor( "Color Name");
16   
17           SCircle circle = new SCircle(20);
18           SSquare square = new SSquare(20);
19           SPainter painter = new SPainter("Deterministic Program", 800, 800);
20           painter.setColor(Color.BLACK);
21   
22           int i=0;
23           while(i < nrOfSquares) {
24               painter.mlt(25);
25               painter.draw(square);
26               i++;
27           }
28   
29           if (color.equalsIgnoreCase("red")) {
30               painter.mrt(225);
31               painter.setColor(Color.RED);
32               painter.paint(circle);
33           }
34           else {
35               painter.mrt(225);
36               painter.setColor(Color.CYAN);
37               painter.paint(circle);
38           }
39       }
40   
41       private String getColor(String Color_Name) {
42           String nss = JOptionPane.showInputDialog(null, Color_Name+"?");
43           Scanner scanner = new Scanner(nss);
44           return scanner.next();
45       }
46   
47   
48       private int getNumber(String Number_of_Squares) {
49           String nss = JOptionPane.showInputDialog(null, Number_of_Squares + "?");
50           Scanner scanner = new Scanner(nss);
51           return scanner.nextInt();
52       }
53   
54       public Invention1() {
55           paintTheImage();
56       }
57   
58       public static void main(String[] args) {
59           SwingUtilities.invokeLater(new Runnable() {
60               public void run() {
61                   new Invention1();
62               }
63           });
64       }
65   }
66