create Polygon - Java 2D Graphics

Java examples for 2D Graphics:Polygon

Description

create Polygon

Demo Code


//package com.java2s;
import java.awt.Point;
import java.awt.Polygon;

public class Main {
    public static Polygon createPolygon(int[] x, int[] y) {
        if (x.length != y.length)
            return null;
        Polygon p = new Polygon();
        for (int i = 0; i < x.length; i++) {
            p.addPoint(x[i], y[i]);/*  ww  w. j a va  2 s .  c om*/
        }
        return p;
    }

    public static Polygon createPolygon(Point[] pts) {
        Polygon p = new Polygon();
        for (int i = 0; i < pts.length; i++) {
            p.addPoint(pts[i].x, pts[i].y);
        }
        return p;
    }
}

Related Tutorials