by Dinesh Thakur Category: Java 2D Example

The QuadCurve2D class lets build a curved segment based on mathematical equations. The curve generated is also called curve quadratic Bezier and based on a very simple idea is to establish two points that define the ends of a curved segment and a third point, called checkpoint that allows "stretching" more or less the curvature of the segment.

Following is at able that lists some of the Constructors and methods of QuadCurve2D class:

 Constructors and Methods Description QuadCurve2D.Double () Creates a QuadCurve2D from (0, 0) to (0, 0), with control point (0,0) QuadCurve2D.Double (double X1, double Y1, double CX1, double CY1, double X2, double Y2) Creates a QuadCurve2D from (X1, Y1) to (X2, Y2), with control point (CX1, CY1). QuadCurve2D.Float () Creates a QuadCurve2D from (0, 0) to (0, 0), with control points (0,0). QuadCurve2D.Float (float X1, float Y1, float CX1, float CY1, float X2, float Y2) Creates a QuadCurve2D from (X1, Y1) to (X2, Y2), with control point (CX1, CY1). boolean intersects (double X, double Y, double Width, double Height) Returns true iff the rectangle described by (X, Y, Width, Height) intersects the QuadCurve void setCurve (double X1, double Y1, double CX1, double CY1, double X2, double Y2) Sets the ends of the QuadCurve as (X1, Y1) and (X2, Y2).

Drawingan Curve exampleshownthecodeas follows:

```import java.applet.Applet;

import java.awt.*;

import java.awt.event.*;

import java.awt.Color;

import java.awt.Graphics;

import javax.swing.*;

import java.awt.geom.*;

import java.awt.image.*;

public class DrawQuadCurve2DExample extends Applet {

public static void main(String[] args) {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

}

public void paint(Graphics g) {

g.setColor(Color.blue);

g.setFont(new Font("Arial",Font.BOLD,14));

g.setFont(new Font("Arial",Font.BOLD,10));

g.drawString("http://ecomputernotes.com", 200, 205);

super.paint(g);

Graphics2D G2D = (Graphics2D)g;

G2D.setColor(Color.green);

G2D.setStroke(new BasicStroke(3.0f));

G2D.draw(QC2D);

G2D.setColor(Color.red);

G2D.draw(new Rectangle2D.Float(40.0f, 70.0f, 1.0f, 1.0f));

G2D.draw(new Rectangle2D.Float(40.0f, 170.0f, 1.0f, 1.0f));

G2D.draw(new Rectangle2D.Float(190.0f, 220.0f, 1.0f, 1.0f));

}

}

```

Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles