OvalRectApplet

OvalRectApplet - //this figure x = (int)(Math.random() *...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
//Java applet to draw ovals and rectangles / import java.awt.*; import javax.swing.*; i public class OvalRectApplet extends JApplet { private final int SIZE = 200; public void paint(Graphics g) { int shape; int numOfFigures; int x; int y; int width; int height; int red; int green; int blue; int i; //determine the number of figures numOfFigures = 5 + (int)(Math.random() * 10); for (i = 0; i < numOfFigures; i++) { red = (int)(Math.random() * 256); //red component green = (int)(Math.random() * 256);//green component blue = (int)(Math.random() * 256); //blue component g.setColor(new Color(red, green, blue)); //color for
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //this figure x = (int)(Math.random() * SIZE); //x value y = (int)(Math.random() * SIZE); //y value width = (int)(Math.random() * SIZE); //width height = (int)(Math.random() * SIZE); //height shape = (int)(Math.random() * 4); /** * 0 : Rectangle * 1 : Filled Rectangle * 2 : Oval * 3 : Filled Oval * **/ switch (shape) { case 0: g.drawRect(x, y, width, height); break; case 1: g.fillRect(x, y, width, height); break; case 2: g.drawOval(x, y, width, height); break; case 3: g.fillOval(x, y, width, height); }//end switch }//end for } }...
View Full Document

This note was uploaded on 06/17/2011 for the course COMP 2301 taught by Professor Staff during the Spring '10 term at Kennesaw.

Page1 / 2

OvalRectApplet - //this figure x = (int)(Math.random() *...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online