Java Reference
In-Depth Information
objects encapsulating curves. You draw the curves in the paint() method by calling the draw() method
for the Graphics2D object and passing a reference to a curve object as the argument. The classes that
define curves implement the Shape interface so any curve object can be passed to the draw() method
that has a parameter of type Shape .
It's hard to see how the control points affect the shape of the curve, so let's add some code to draw the
control points.
TRY IT OUT: Displaying the Control Points
You can mark the position of each control point by drawing a small circle around it that I'll call a marker.
You will be able to move a control point around by dragging the marker with the mouse and see the effect
on the curve. You can define a marker using an inner class of CurveApplet that you can define as fol-
lows:
// Inner class defining a control point marker
private class Marker {
public Marker(Point2D.Double control) {
center = control;
// Save control point as
circle center
// Create circle around control point
circle = new Ellipse2D.Double(control.x-radius,
control.y-radius,
2.0*radius, 2.0*radius);
}
// Draw the marker
public void draw(Graphics2D g2D) {
g2D.draw(circle);
}
// Get center of marker - the control point position
Point2D.Double getCenter() {
return center;
}
Ellipse2D.Double circle;
// Circle around control
point
Point2D.Double center;
// Circle center - the
control point
static final double radius = 3;
// Radius of circle
}
Directory "CurveApplet 2 displaying control points"
Search WWH ::




Custom Search