Draws a polygon in the specified color. - Java 2D Graphics

Java examples for 2D Graphics:Polygon

Description

Draws a polygon in the specified color.

Demo Code


//package com.java2s;
import java.awt.*;

public class Main {
    /** Draws a polygon in the specified color.
     *  Having a drawPolygon with a line width argument
     *  would be nice, but you can't just do it by
     *  drawing thick lines, since you could jagged
     *  corners. Filling in those corners takes more
     *  work, so is postponed. If someone wants to
     *  implement this and send it to me, it would
     *  be great.//  w  w w  .  j a  va  2  s  .c  o  m
     */

    public static void drawPolygon(Graphics g, int[] xPoints,
            int[] yPoints, int numPoints, Color c) {
        Color origColor = g.getColor();
        g.setColor(c);
        g.drawPolygon(xPoints, yPoints, numPoints);
        g.setColor(origColor);
    }

    /** Draws a polygon in the specified color. */

    public static void drawPolygon(Graphics g, Polygon p, Color c) {
        Color origColor = g.getColor();
        g.setColor(c);
        g.drawPolygon(p);
        g.setColor(origColor);
    }
}

Related Tutorials