This section illustrates you how to create GeneralPath. We have used the class GeneralPath to create three different shapes. For this, we have create three objects of class GeneralPath i.e, path1, path2, path3.
The method moveTo(25, 35) adds a point to the path by moving to the coordinates (25, 35). The method lineTo(35, 50) draw a straight line from the current coordinates to the new specified coordinates (35, 50). The method curveTo(20, 100, 110, 60, 40, 100) adds a curved segment, to the path by drawing a curve that intersects both the current coordinates and the new specified coordinates (control points).
The Vector class represents an array of objects. The method addElement() adds the given component to the vector by increasing its size by one. The method elementAt(i) returns the component at the index.
Here is the code of ShowGeneralPath.java
Output will be displayed as:
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial