GBall.java
Retired DISLab
/* * File: GBall.java * ---------------- * This file defines a GObject class that represents a ball. */ import acm.graphics.*; /** * This class defines a GCompound subclass that represents a ball * whose reference point is the center rather than the upper * left corner. */ public class GBall extends GCompound { /** Creates a new ball with radius r centered at the origin */ public GBall(double r) { radius = r; ball = new GOval(2 * radius, 2 * radius); ball.setFilled(true); add(ball, -radius, -radius); markAsComplete(); } /** Creates a new ball with radius r centered at (x, y) */ public GBall(double r, double x, double y) { this(r); setLocation(x, y); } public void setRadius(double r) { ball.setSize(r * 2, r * 2); } public double getRadius() { return radius; } /* public void setSize(double r) { ball.setSize(r, r); } public double getWidth() { return ball.getWidth(); } public double getHeight() { return ball.getHeight(); } */ private GOval ball; private double radius; }