Draw different curves with QuadCurve2D

The QuadCurve2D class provides a quadratic parametric curve segments. We are providing you an example which shows different curves.

Draw different curves with QuadCurve2D

The QuadCurve2D class provides a quadratic parametric curve segments. We are providing you an example which shows different curves.

Draw different curves with QuadCurve2D

Draw different curves with QuadCurve2D

     

This section illustrates you how to draw different curves with the class QuadCurve2D.

The QuadCurve2D class provides a quadratic parametric curve segments. We are providing you an example which shows different curves.

In the given example, we have used Vector class to implement an array of objects. The components of this class can be accessed using an index. The method vector.size() of Vector class returns the number of components in the vector. The method vector.elementAt(k) returns the component at the specified index, in this example we have used 'k' as index.

Here is the code of QuadCurveExample.java

import java.awt.*;
import javax.swing.*;
import java.util.Vector;
import java.awt.geom.QuadCurve2D;
import java.awt.geom.Rectangle2D;

public class QuadCurveExample extends JApplet {
 Canvas1 canvas;
public static void main(String[] args){
  JFrame frame = new JFrame("QuadCurve Example");
  QuadCurveExample curve = new QuadCurveExample();
  curve.init();
  frame.getContentPane().add(curve);
  frame.setSize(500,250);
  frame.setVisible(true);
  }
  public void init() {
  Container container = getContentPane();
  canvas = new Canvas1();
  container.add(canvas);
  }
  class Canvas1 extends Canvas {
  Vector vector;
  QuadCurve2D quadCurve = null;
  Rectangle2D rec = null;

  public Canvas1() {
  setBackground(Color.white);
  setSize(500250);

  vector = new Vector();
  vector.addElement(new QuadCurve2D.Float(303090
   170
130,30));
  vector.addElement(new QuadCurve2D.Float(130110170
  
50210,190));
  vector.addElement(new QuadCurve2D.Float(25030230
   70270,130));
  vector.addElement(new QuadCurve2D.Float(260170270,
    
150,290190));
 vector.addElement(new QuadCurve2D.Float(280180280
  160
,300190));
  vector.addElement(new QuadCurve2D.Float(310190350
  50
390,130));
  vector.addElement(new QuadCurve2D.Float(3019090
  180
130,200));
  vector.addElement(new QuadCurve2D.Float(14040100
 
190140,200));
  }
 public void paint(Graphics g) {
  Graphics2D g2 = (Graphics2D) g;
 for (int k = 0; k < vector.size(); k++) {
  g2.draw((QuadCurve2D) vector.elementAt(k));
  }
}
  }
}

Output will be displayed as:

Download Source Code