Java examples for java.awt:Graphics2D
Draws polygon filled with color from points
import java.util.ArrayList; import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.geom.*; public class Main{ /**/*from www . j a v a2 s . c o m*/ * Draws polygon filled with color from points */ public static void drawFilledPolygon(Graphics2D g, ArrayList<Point> points, Color color) { Path2D polygon_path = new Path2D.Double(); polygon_path.moveTo(points.get(0).getX(), points.get(0).getY()); for (int i = 1; i < points.size(); i++) { polygon_path.lineTo(points.get(i).getX(), points.get(i).getY()); } polygon_path.closePath(); g.setPaint(color); g.fill(polygon_path); } }