Java Reference
In-Depth Information
}
public Shape getShape() {
return curve;
}
public java.awt.Rectangle getBounds() {
return curve.getBounds();
}
private GeneralPath curve;
}
}
The Curve class constructor creates a GeneralPath object and adds a single line segment to it by
moving the current point to start by calling moveTo() , and then calling its lineTo() method with
next as the argument. Additional segments are added by the modify() method. This calls lineTo()
for the GeneralPath member of the class with the new point as the argument. This will add a line
from the end of the last segment that was added to the new point.
Try It Out - Drawing Curves
Of course, we need to uncomment the line creating
an Element.Curve object in the
createElement() method. Then we are ready to
roll again. If we recompile Sketcher we will be able
to give freehand curves a whirl, and produce elegant
sketches such as that here.
How It Works
Drawing curves works in essentially the same way as drawing the other elements. The use of XOR
mode is superfluous with drawing a curve since we only extend it, but it would be quite a bit of work to
treat it as a special case. This would only be justified if drawing curves was too slow and produced
excessive flicker.
You may be wondering if you can change from XOR mode back to the normal mode of drawing in a
graphics context. Certainly you can: just call the setPaintMode() method for the graphics context
object to get back to the normal drawing mode.
Search WWH ::




Custom Search