/* ComboDrawApp.java Seminar 7 - Graphical User Interface (GUI) POST in Sem 7 folder DQs #2 2.Write a program that allows the user to select a shape from a JComboBox and that then draws that shape 20 times with random locations and dimensions in method paint(). The first item in the JComboBox should be the default shape that is displayed the first time paint() is called. Be sure to use the elements specified in the DQ in order to get some experience with basic GUI elements! */ /** * * @author Darren Frendo */ import java.awt.Color; import java.awt.Graphics; import javax.swing.JPanel; import java.util.Random; import java.util.*; public class DrawShapeRect extends JPanel { private int x; private int y; private int h; private int w; Random randomNumbers = new Random(); // class to draw Rectangle public void paintComponent( Graphics g) { super.paintComponent( g ); // call superclass's paint method int counter = 20; while (counter > 1) { counter--; //initiating x cordinate, y cordinate, w width, h height x=1; y=1; w=1; h=1; x = randomNumbers.nextInt( 200 ); y = randomNumbers.nextInt( 200 ); h = randomNumbers.nextInt( 200 ); w = randomNumbers.nextInt( 200 ); this.setBackground( Color.WHITE ); g.setColor( Color.BLUE ); g.drawRect( x, y, w, h ); } //end of while loop } // end method paintComponent } // end class