/** * 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 Color color; private boolean filled; /** * static keyword: belongs to class, shared among all instances o anything static exists as soon as class is created (compiled) _before_ any instance of the class is created o static methods can access in their body only the stuff that are static o can be accessed via class name (recommended) OR instances o typically used in - truly shared resources - accounting - generate unique values such as id, serial number - methods: no need to access instance member variables/methods */ // 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) { // this: // (1) differentiate member variable from parameter or local variable // (2) call (refer to) yourself // (3) call your own constructor in the same class this(x, y, r, canvas.randomColor(), 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 cx, int y, int r, Color c, boolean f) { this.cx = cx; 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); } } }