Java Reference
In-Depth Information
default constructor to create a curve object with all the fields set to 0 and set them yourself. The following
statements create the same curve as the previous fragment:
CubicCurve2D.Double cubicCurve = new CubicCurve2D.Double();
cubicCurve.x1 = 50;
cubicCurve.y1 = 300;
cubicCurve.x2 = 150;
cubicCurve.y2 = 300;
cubicCurve.ctrlx1 = 80;
cubicCurve.ctrly1 = 250;
cubicCurve.ctrlx2 = 160;
cubicCurve.ctrly2 = 250;
Of course, you could use the same approach to create a quadratic curve.
You can understand these curve classes better if you try them out. This time let's do it with an applet.
TRY IT OUT: Drawing Curves
You can define an applet to display the curves that I used as examples in the previous section:
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
@SuppressWarnings("serial")
public class CurveApplet extends JApplet {
// Initialize the applet
@Override
public void init() {
pane = new CurvePane();
// Create pane
containing curves
Container content = getContentPane();
// Get the content pane
// Add the pane displaying the curves to the content pane for the
applet
content.add(pane);
// BorderLayout.CENTER is
default position
}
// Class defining a pane on which to draw
class CurvePane extends JComponent {
// Constructor
public CurvePane() {
quadCurve = new QuadCurve2D.Double(
// Create
quadratic curve
startQ.x, startQ.y,
// Segment
start point
control.x, control.y,
// Control point
Search WWH ::




Custom Search