/* * Shapes.java * * Created on April 22, 2007, 12:46 PM * * by Joseph Shemeta for MSCSHR-JV-070308-01 * SEM7DQ2 * * * */ import java.awt.Color; import java.awt.Graphics; import javax.swing.JPanel; import java.util.Random; public class Shapes extends JPanel{ int selection = 0; //Here's where we find out which panel to draw int max_x1 = 200; //Setting up the MAX values that random will use int max_x2 = 600; int max_y1 = 200; int max_y2 = 600; int max_width = 400; int max_height = 400; int max_AW = 400; int max_AH = 400; int x1, x2, y1, y2, arcWidth, arcHeight, width, height; Random randomNum = new Random(); public Shapes(int userChoice){ selection = userChoice; //Here's were we get the image choice from the user }//END public Shapes public void paintComponent( Graphics g ){ super.paintComponent( g ); // call superclass's paint method this.setBackground( Color.WHITE ); for(int i=0; i<20;i++){ x1 = randomNum.nextInt(max_x1); //All shapes use these so I make them here y1 = randomNum.nextInt(max_y1); //Ramdom colors make things more interesting g.setColor( new Color(randomNum.nextInt(255),randomNum.nextInt(255),randomNum.nextInt(255)) ); switch(selection){ case 0: x2 = randomNum.nextInt(max_x2); y2 = randomNum.nextInt(max_y2); g.drawLine( x1, y1, x2, y2 ); //Draw a line break; case 1: width = randomNum.nextInt(max_width); height = randomNum.nextInt(max_height); g.drawRect( x1, y1, width, height );//Draw a Rectangle break; case 2: width = randomNum.nextInt(max_width); height = randomNum.nextInt(max_height); arcWidth = randomNum.nextInt(max_AW); arcHeight = randomNum.nextInt(max_AH); g.drawRoundRect( x1, y1, width, height, arcWidth, arcHeight );//Draw a Rounded Rectangle break; case 3: width = randomNum.nextInt(max_width); height = randomNum.nextInt(max_height); g.draw3DRect( x1, y1, width, height, true );//Draw a "3D" Rectangle break; case 4: width = randomNum.nextInt(max_width); height = randomNum.nextInt(max_height); g.drawOval(x1, y1, width, height );//Draw an Oval break; }//END switch }//END for } //END public void paintComponent } //END public class Shapes