1 /* 2 * A program to paint, centered on the canvas, a circle of randomly colored, black-framed squares. 3 */ 4 5 package npw; 6 7 import painter.SPainter; 8 import shapes.SCircle; 9 import shapes.SSquare; 10 11 import javax.swing.*; 12 import java.awt.*; 13 import java.util.Scanner; 14 15 public class Invention1 { 16 private void paintTheImage() { 17 SPainter klee = new SPainter("Invention 1", 600, 600); 18 SCircle dot = new SCircle(200); 19 SSquare square = new SSquare(400); 20 21 String command = getString("Square or target?"); 22 int number = getNumber("Enter the number of targets inside of a target, or squares inside of a square."); 23 int i = 0; 24 25 while( i < number ) { 26 27 if (command.equalsIgnoreCase("target")) { 28 //First Red Circle 29 klee.setColor(Color.MAGENTA); 30 klee.paint(dot); 31 32 //White Circle 33 dot.s3(); 34 dot.x2(); 35 klee.setColor(Color.cyan); 36 klee.paint(dot); 37 38 //Second Red Circle 39 dot.s2(); 40 klee.setColor(Color.yellow); 41 klee.paint(dot); 42 } else { 43 //First Red Circle 44 klee.setColor(Color.magenta); 45 klee.paint(square); 46 47 //White Circle 48 square.s3(); 49 square.x2(); 50 klee.setColor(Color.cyan); 51 klee.paint(square); 52 53 //Second Red Circle 54 square.s2(); 55 klee.setColor(Color.yellow); 56 klee.paint(square); 57 } 58 i = i + 1; 59 } 60 61 } 62 63 private static int getNumber(String prompt) { 64 String nss = JOptionPane.showInputDialog(null,prompt+"?"); 65 Scanner scanner = new Scanner(nss); 66 return scanner.nextInt(); 67 } 68 69 private static String getString(String prompt) { 70 String nss = JOptionPane.showInputDialog(null,prompt+"?"); 71 Scanner scanner = new Scanner(nss); 72 return scanner.next(); 73 } 74 75 //REQUIRED INFRASTRUCTURE 76 77 public Invention1() { 78 paintTheImage(); 79 } 80 81 public static void main(String[] args) { 82 SwingUtilities.invokeLater(new Runnable() { 83 public void run() { 84 new Invention1(); 85 } 86 }); 87 } 88 } 89 90 91