Java Reference
In-Depth Information
Constructor
Description
GeneralPath()
Defines a general path with a default winding rule of
WIND
_
NON
_
ZERO
.
GeneralPath(int rule)
Creates an object with the winding rule specified by
the argument. This can be
WIND
_
NON
_
ZERO
or
WIND
_
EVEN
_
ODD
.
GeneralPath(int rule,
int capacity)
Creates an object with the winding rule specified by
the first argument and the number of path segments
specified by the second argument. In any event, the
capacity is increased when necessary.
GeneralPath(Shape shape)
Creates an object from the object passed as an
argument.
We can create a
GeneralPath
object with the statement:
GeneralPath p = new GeneralPath(GeneralPath.WIND
_
EVEN
_
ODD);
A
GeneralPath
object embodies the notion of a current point of type
Point2D
from which the next
path segment will be drawn. You set the initial current point by passing a pair of (
x
,
y
) coordinates as
values of type
float
to the
moveTo()
method for the object. For example:
p.moveTo(10.0f,10.0f); // Set the current point to 10,10
A segment is added to the general path, starting at the current point, and the end of each segment that
you add becomes the new current point that is used to start the next segment. Of course, if you want
disconnected segments in a path, you can call
moveTo()
to move the current point to wherever you
want before you add a new segment. If you need to get the current position at any time, you can call the
getCurrentPoint()
method for a
GeneralPath
object and get the current point as type
Point2D
.
You can use the following methods to add segments to a
GeneralPath
object:
Methods to Add Segments
Description
lineTo(float x, float y)
Draws a line from the current point to the point (
x,y
).
quadTo(float ctrlx,
float ctrly,
float x2, float y2)
Draws a quadratic curve segment from the current
point to the point (
x2,y2
) with (
ctrlx,ctrly
) as the
control point.
curveTo(float ctrlx1,
float ctrly1,
float ctrlx2, float
ctrly2,
float x2, float y2)
Draws a Bezier curve segment from the current point
with control point (
ctrlx1,ctrly1
) to (
x2,y2
) with
(
ctrlx2,ctrly2
) as the control point.