/home/ssingh6/NetBeansProjects/CS1/src/npw/Number4.java
  1 /*
  2  * To change this license header, choose License Headers in Project Properties.
  3  * To change this template file, choose Tools | Templates
  4  * and open the template in the editor.
  5  */
  6 package npw;
  7 
  8 import java.awt.Color;
  9 import java.util.Random;
 10 import java.util.Scanner;
 11 import javax.swing.JOptionPane;
 12 import javax.swing.SwingUtilities;
 13 import painter.SPainter;
 14 import shapes.SCircle;
 15 
 16 /**
 17  *
 18  * @author ssingh6
 19  */
 20 public class Number4 {
 21 
 22     /**
 23      * @param args the command line arguments
 24      */
 25     public static void main(String[] args) {
 26     SwingUtilities.invokeLater(new Runnable() {
 27               public void run() {
 28                   new Number4();
 29               }
 30           });
 31       }
 32       
 33       public Number4() {
 34           paintTheImage();
 35       }
 36       
 37       // THE SOLUTION TO THE GRAPHICAL PROBLEM
 38       
 39       private void paintTheImage() {
 40           // GRAB THE INPUT INFORMATION
 41           int nrOfRows = getNumber("rows");
 42           int nrOfColumns = getNumber("columns");
 43           int diameterOfCircle = getNumber("circle diameter");
 44           String color = getColor("color");
 45          // ESTABLISH THE PAINTER
 46           int height = nrOfRows * diameterOfCircle;
 47           int width = nrOfColumns * diameterOfCircle;
 48           SPainter micro = new SPainter("Number 4",width+50,height+50);
 49          micro.setBrushWidth(4);
 50           SCircle circle = new SCircle(diameterOfCircle);
 51           // PAINT THE RECTANGLES
 52           paintRectangle(micro,circle,nrOfRows,nrOfColumns,color);
 53       }
 54   
 55       private int getNumber(String prompt) {
 56           String nss = JOptionPane.showInputDialog(null,prompt+"?");
 57           Scanner scanner = new Scanner(nss);
 58           return scanner.nextInt();
 59       }
 60   
 61       private void paintRectangle(SPainter micro, SCircle circle , int nrOfRows, int nrOfColumns,String color) {
 62           // POSITION THE PAINTER TO PAINT THE RECTANGLE OF CIRCLES
 63           micro.mlt(((nrOfColumns-1)/2.0) * circle.diameter());
 64           micro.mbk(((nrOfRows-1)/2.0) * circle.diameter());
 65           // PAINT THE RECTANGLE OF CIRCLES
 66           int i = 1;
 67           while (i <= nrOfRows) {
 68               paintOneRow(micro,nrOfColumns,circle,color);
 69               micro.mfd(circle.diameter());
 70               i = i + 1;
 71           }
 72           micro.mrt(((nrOfColumns-1)/2.0) * circle.diameter());
 73           micro.mfd(((nrOfRows-1)/2.0) * circle.diameter());
 74       }
 75   
 76       private void paintOneRow(SPainter micro, int nrOfColumns, SCircle circle,String color) {
 77           int i = 1;
 78           while ( i <= nrOfColumns ) {
 79               paintOneSquare(micro,circle,color);
 80               micro.mrt(circle.diameter());
 81              i = i + 1;
 82           }
 83           micro.mlt(nrOfColumns * circle.diameter());
 84       }
 85   
 86       private void paintOneSquare(SPainter micro, SCircle circle,String color) {
 87           circle.s2();
 88        if(color.equalsIgnoreCase("red"))
 89        {
 90            micro.setColor(Color.RED);
 91        }
 92        else if (color.equalsIgnoreCase("blue"))
 93        {
 94            micro.setColor(Color.BLUE);
 95            
 96        }
 97        else if(color.equalsIgnoreCase("green"))
 98        {
 99            micro.setColor(Color.GREEN);
100        }
101        else {
102        micro.setColor(Color.BLACK);
103        }
104           
105           micro.paint(circle);
106           
107           circle.x2();
108          
109       }
110   
111      
112 
113     private String getColor(String prompt) {
114        String color = JOptionPane.showInputDialog(null,prompt+"?");
115        Scanner scanner = new Scanner(color);
116        return scanner.next();
117     }
118      
119  }   
120   
121     
122    
123 
124     
125    
126