/* * ============================================================= * SimpleCircle.java : This class stores the radius and the * x and y coordinates. Also draws a circle at the given coordinates. * * Adapted from : Hall M., Core Web Programming, 1997 * Modified by : Vasilios Lagakos March, 2001 * ============================================================== */ import java.awt.*; public class SimpleCircle { private int x, y, radius, grid = 10; public SimpleCircle(int x, int y, int radius) { setX(x); setY(y); setRadius(radius); } /** Given a Graphics, draw a checkered background and the SimpleCircle * centered around its current position. */ public void draw(Graphics g, int width, int height) { Graphics2D g2 = (Graphics2D)g; int w = width /grid; int h = height / grid; boolean black = false; for (int i=0; i<=grid; i++) for (int j=0; j<= grid; j++) { g2.setPaint(black ? Color.black : Color.white); black = !black; g2.fillRect(j*w, i*h, w, h); } g2.setPaint(Color.green); g2.fillOval(x - radius, y - radius, radius * 2, radius * 2); } public int getX(){return(x);} public void setX(int x) { this.x = x; } public int getY(){return(y);} public void setY(int y) { this.y = y; } public int getRadius(){return(radius);} public void setRadius(int radius) { this.radius = radius; } }