Square -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//*************************************************************** // Square.java // // Represents a graphical Square with a size, position (upper // left corner), and color. //*************************************************************** import java.util.Random; import java.awt.*; public class Square { private final int MAX_COLOR_CODE = 16777215; // Instance variables int size; int x, y; Color color; // Instantiate a random number generator private static Random generator = new Random(); //---------------------------------------------------------- // Constructor - sets up a random square
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //----------------------------------------------------------public Square() { size = generator.nextInt(100) + 100; x = generator.nextInt(600); y = generator.nextInt(400); int colorCode = generator.nextInt(MAX_COLOR_CODE); color = new Color (colorCode); } //----------------------------------------------------------// Draws the square on the given Graphics object. //----------------------------------------------------------public void draw(Graphics page) { page.setColor(color); page.fillRect(x, y, size, size); } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Ask a homework question - tutors are online