Circle circ = new Circle();
This creates a Circle
object.
The object has none of its values for x, y, radius, or colors filled in.
This OK.
Later on, these values can be set before the circle is drawn.
Circle
A Circle
is a kind of Shape
which is a kind of Node
which is a kind of Object
.
Other Shape
s are Rectangle
and Line
,
which we will see later in these notes.
Another type of Node
is a Parent
.
More on this in another chapter.
Here are some of the Circle
constructors.
For details, look at the Oracle documentation.
Circle() Create an empty instance of Circle. Circle( double radius ) Create a Circle with a specified radius. The default fill color is black. The default stroke color is null. Circle(double centerX, double centerY, double radius) Create a Circle with a specified position and radius. The default fill color is black. The default stroke color is null. Circle(double centerX, double centerY, double radius, Paint fill) Create a Circle with a specified position, radius and fill. Circle(double radius, Paint fill) Create a Circle with a specified radius and fill color.
Here are some of the Circle
methods.
You can construct a Circle
object
with one of the constructors, and then later on adjust its size, color, and location.
double getCenterX() Gets the value of centerX. double getCenterY() Gets the value of centerY. double getRadius() Gets the value of the radius. void setCenterX(double value) Sets the value of centerX. void setCenterY(double value) Sets the value of centerY. void setRadius(double value) Sets the value of radius.
Here are some useful methods inherited from Shape
:
public final void setFill(Paint value) Set the color for the fill. public final Paint getFill() Get the color of the fill. public final void setStroke(Paint value) Set the color for the stroke public final Paint getStroke() Get the color of the stroke public final void setStrokeWidth(double value) Set the width of the stroke, in pixels public final Paint getStrokeWidth() Gets the width of the stroke, in pixels
Notice that Circle
s are mutable: the instance variables of a Circle
object can be changed as
a program is running.
Oracle Documentation for Shape
All Shape
s have a fill color (the color that fills it)
and a stroke color (the color of the outline.)
(Thought Question: ) How would you change this statement
to make the fill color of the Circle
red?
circle.setFill( Color.GREEN );