package chapter2; import java.awt.Color; import java.awt.Rectangle; import java.util.Random; import java.util.Scanner; import javax.swing.JFrame; public class RectangleDrawing { public static void main(String[] args) { //ask user for size of rectangle Scanner in = new Scanner(System.in); System.out.println("Enter height of rectangle: "); int height = in.nextInt(); System.out.println("Enter width of rectangle: "); int width = in.nextInt(); //generate a random color by mixing amounts of Red, Green, and Blue Random rng = new Random(); Color myColor = new Color(rng.nextInt(256), rng.nextInt(256), rng.nextInt(256)); //make a Rectangle of this size Rectangle box = new Rectangle (5,10, width, height); //make a drawable version of the Rectangle RectangleComponent rectToDraw = new RectangleComponent(box, myColor); //make a frame for the drawing to occur in JFrame frame = new JFrame(); frame.setSize(300,400); frame.setTitle("Rectangle"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //end the program when the window is closed //put the drawable rectangle in the frame we made frame.add(rectToDraw); //allow us to see our drawing frame.setVisible(true); } }