View RSS Feed

Java AWT

Drawing Arbitrary Shapes

Rate this Entry
by , 03-06-2012 at 08:56 PM (848 Views)
This class is used to implement shape interface. It also presents geometric path that is constructed from:
  • Lines
  • Cubic Curves
  • Quadratic

This class supports 3 constructors which creates GeneralPath. These constructors are supported by class along with default winding rule i.e. WIND_NON_ZERO, specified initial coordinate capacity and winding rule i.e. WIND_NON_ZERO or WIND_EVEN_ODD

How to determine interior of a path is specified by using the winding rule.
Java Code:
public void Paint (Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
Call new GeneralPath() for creation of empty GeneralPath. Then segments are added to shape, by these methods.

  • moveTo(float x, float y) –Current point of the path is moved to the given point
  • lineTo(float x, float y) –line segment is added to the current path
  • quadTo(float ctrlx, float ctrly, float x2, floaty2) –To the current path, quadratic curve segment is added.
  • curveTo(float ctrlx1, float ctrly1, float ctrlx2, float ctrly2, float x3, floaty3) – To the current path, cubic curve segment is added.
  • closePath() – Current path is closed.

Submit "Drawing Arbitrary Shapes" to Facebook Submit "Drawing Arbitrary Shapes" to Digg Submit "Drawing Arbitrary Shapes" to Submit "Drawing Arbitrary Shapes" to StumbleUpon Submit "Drawing Arbitrary Shapes" to Google