# Circle - Draws circle on the graphics object given-public...

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

// **************************************************************** // Circle.java // // Define a Circle class with methods to create and draw // a circle of random size, color, and location. // // **************************************************************** import java.awt.*; import java.util.Random; public class Circle { private int centerX, centerY; private int radius; private Color color; static Random generator = new Random(); //--------------------------------------------------------- // Creates a circle with center at point given, random radius and color // -- radius 25. .74 // -- color RGB value 0. .16777215 (24-bit) //--------------------------------------------------------- public Circle(Point point) { radius = Math.abs(generator.nextInt())%50 + 25; color = new Color(Math.abs(generator.nextInt())% 16777216); centerX = point.x; centerY = point.y; } //---------------------------------------------------------

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Draws circle on the graphics object given //---------------------------------------------------------public void draw(Graphics page) { page.setColor(color); page.fillOval(centerX-radius,centerY-radius,radius*2,radius*2); } //---------------------------------------------------------// Moves the circle to the given point. //---------------------------------------------------------public void move(Point p) { centerX = p.x; centerY = p.y; } //---------------------------------------------------------// Returns true if the given point is inside the circle, false otherwise. //---------------------------------------------------------public boolean isInside(Point p) { return Math.sqrt((centerX-p.x)*(centerX-p.x)+(centerY-p.y)*(centerY-p.y)) < radius; } }...
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.

### Page1 / 2

Circle - Draws circle on the graphics object given-public...

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

View Full Document
Ask a homework question - tutors are online