Java Reference
In-Depth Information
cubicCurve.setStartY(75);
// start pt (x1,y1)
cubicCurve.setControlX1(80);
cubicCurve.setControlY1(-25); // control pt1
cubicCurve.setControlX2(110);
cubicCurve.setControlY2(175); // control pt2
cubicCurve.setEndX(140);
cubicCurve.setEndY(75);
cubicCurve.setStrokeType(StrokeType.CENTERED);
cubicCurve.setStrokeWidth(1);
cubicCurve.setStroke(Color.BLACK);
cubicCurve.setStrokeWidth(3);
cubicCurve.setFill(Color.WHITE);
You begin by instantiating a
CubicCurve()
instance. Next, the curve's attributes
are specified in any order by utilizing the object's setter methods and passing a single
value to each. Once you're finished specifying values on the
CubicCurve()
object,
you can add it to the scene graph using the following notation:
root.getChildren().add(cubicCurve);
The ice cream cone shape is created using the
javafx.scene.shape.Path
class. As each path element is created and added to the
Path
object, each element is
not
considered a graph node (
javafx.scene.Node
). This means they do not ex-
tend from the
javafx.scene.shape.Shape
class and cannot be a child node in a
class that extends from the (
javafx.scene.Node
) class, and therefore a
Path
is a
graph node, but path elements do not extend from the
Shape
class. Path elements ac-
tually extend from the
javafx.scene.shape.PathElement
class, which is
only used in the context of a
Path
object. So you won't be able to instantiate a
LineTo
class to be put in the
scene
graph. Just remember that the classes with
To
as
a suffix are path elements, not real
Shape
nodes. For example, the
MoveTo
and
LineTo
object instances are
Path
elements added to a
Path
object, not shapes that
can be added to the scene. The following are
Path
elements added to a
Path
object to
draw an ice cream cone: