This Java tip demonstrates a method of drawing basic shapes using lines and curves on a Java component. The basic shapes can be drawn by a developer overwriting the paint() function of the component.

 // x, y, controlpointx, controlpointy,controlpointx1, controlpointy1, 
    // controlpointx2, controlpointy2 may be define by the developer
    GeneralPath shape = new GeneralPath();
    shape.moveTo(x, y);
    shape.lineTo(x, y);
    shape.quadTo(controlPointX, controlPointY, x, y);
    shape.curveTo(controlPointX1, controlPointY1, controlPointX2, 
      controlPointY2, x, y);

Parent Category: Java SE Tips