Circle - // Draws circle on the graphics object given

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

View Full Document Right Arrow Icon
// **************************************************************** // 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; } //---------------------------------------------------------
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: // 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

Page1 / 2

Circle - // Draws circle on the graphics object given

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