Java - Filling a Custom Shape

Whenever I create a shape, I always create a Path2D.Double object. Then, I use moveTo to get to the starting location, and a combination of lineTo() and curveTo() to move around the path. Then, when I'm done, I call closePath(). It has always filled correctly.

I don't have any experience with implementing getPathIterator, but I do notice that you don't do a closePath(). I don't know if that's required or not, but I do feel like taking my approach will work.

Here is an example that fills a rounded rectangle:

double width = 300;
double height = 400;
Path2D.Double path = new Path2D.Double();
path.moveTo(0.0, 8.0);
path.curveTo(0.0, 0.0, 8.0, 0.0, 8.0, 0.0);
path.lineTo(width - 8.0, 0.0);
path.curveTo(width, 0.0, width, 8.0, width, 8.0);
path.lineTo(width, height - 8.0);
path.curveTo(width, height, width - 8.0, height, width - 8.0, height);
path.lineTo(8.0, height);
path.curveTo(0.0, .height, 0.0, height - 8.0, 0, height - 8.0);
path.closePath();
g2.fill(path);

I don't know much about graphics.But I have seen these examples in sun's site.I'm just posting the link in case you need it. http://java.sun.com/products/java-media/2D/samples/suite/index.html