CONTENTS | PREV | NEXT | Java 2D API |
You can implement the Shape interface to create a class that defines a new type of shape. It doesn't matter how you represent the shape internally, as long as you can implement the Shape interface methods. The Shape must be able to generate a path that specifies it's contour.For example, you could create a simple implementation of Shape that represents polygons as arrays of points. This class, PolygonPath, could define just one new method, addPoint. To build a PolygonPath object, a client would repeatedly call addPoint. Once the polygon is built, it could be passed to draw, setClip, or any other method that expects a Shape object as an argument.
The PolygonPath class must implement the Shape interface methods: