Circle - CoolPotato31F/Java-Graphics GitHub Wiki

Circle Class

Overview

The Circle class is part of the graphics package and implements the GraphicsObject interface. It represents a drawable circle defined by a center point and a radius, supporting various operations such as movement, rendering, and color customization.

Attributes

  • Point point1 - The center point of the circle.
  • int radius - The radius of the circle.
  • Color outlineColor - The outline color of the circle (default: BLACK).
  • int width - The outline width of the circle.
  • GraphWin canvas - Reference to the canvas where the circle is drawn.
  • Color fillColor - The fill color of the circle.

Constructors

Circle(Point p1, int r)

Creates a circle with a given center point and radius.

Parameters:

  • Point p1 - The center point of the circle.
  • int r - The radius of the circle.

Methods

void draw(GraphWin canvas)

Draws the circle on the given canvas.

Parameters:

  • GraphWin canvas - The canvas to draw on.

Throws:

  • Error if the circle is already drawn.

void undraw()

Removes the circle from the canvas.

void setFill(Color color)

Sets the fill color of the circle.

Parameters:

  • Color color - The color to fill the circle with.

void setOutline(Color color)

Sets the outline color of the circle.

Parameters:

  • Color color - The outline color.

void setWidth(int width)

Sets the outline width of the circle.

Parameters:

  • int width - The width of the outline.

void move(double dx, double dy)

Moves the circle by the given x and y amounts.

Parameters:

  • double dx - The amount to move along the x-axis.
  • double dy - The amount to move along the y-axis.

void drawPanel(Graphics2D graphics)

Renders the circle onto a Graphics2D panel.

Parameters:

  • Graphics2D graphics - The graphics object used for rendering.

Point getCenter()

Returns the center point of the circle.

int getRadius()

Returns the radius of the circle.

See Also