/** * CircularStroke.java * * @author Sunny Kim (skim@gettysburg.edu) * * represents a circular stroke with location, color, outline/filled * is used in DrawApp */ import java.awt.Color; import graphics.canvas; public class CircularStroke { /** instance variables, member variables, data members */ private int cx; // getCx, getCX private int cy; private int radius; private static Color color; private boolean filled; // constructor overloading: multiple constructors in the same class // with different parameter list // different number, order/type /** * Constructs a new CircularStroke with given parameters * * @param x center-x * @param y center-y * @param r radius * @param f filled or not */ public CircularStroke(int x, int y, int r, boolean f) { cx = x; cy = y; radius = r; color = canvas.randomColor(); filled = f; } /** * Constructs a new CircularStroke with given parameters * * @param x center-x * @param y center-y * @param r radius * @param c color * @param f filled or not */ public CircularStroke(int x, int y, int r, Color c, boolean f) { cx = x; cy = y; radius = r; color = c; filled = f; } /** accessor methods: selectors (get methods), mutators (set methods) */ // selectors: get methods // access modifier: public, cannot be private // return type : same as the variable to access // method name : get followed by capitalized variable name // parameter list : typically empty // body : typically one liner public int getRadius() { return radius; } // mutators: set methods // return type : typically void // method name : set followed by capitalized variable name // parameter list : typically new value for the variable // body : typically one liner public void setRadius(int r) { radius = r; } /** * Draws on the canvas this circular stroke */ public void draw() { if (filled == true) { canvas.fillCircle(cx, cy, radius, color); } else { canvas.drawCircle(cx, cy, radius, color); } } }