Java Graphics Draw drawFilledOctagon(Graphics2D g, int x, int y, float size)

Here you can find the source of drawFilledOctagon(Graphics2D g, int x, int y, float size)

Description

Draw a filled octagon at the specified position with the specified size

License

Open Source License

Parameter

Parameter Description
g The graphics context to use
x The x position to draw at
y The y position to draw at
size The size of the octagon (width and height)

Declaration

public static void drawFilledOctagon(Graphics2D g, int x, int y, float size) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.*;
import java.awt.geom.*;

public class Main {
    protected static Polygon octagon = null;

    /**/*  www.ja  v a2 s .  c  om*/
     * Draw a filled octagon at the specified position with the specified size
     * @param g      The graphics context to use
     * @param x      The x position to draw at
     * @param y      The y position to draw at
     * @param size   The size of the octagon (width and height)
     */
    public static void drawFilledOctagon(Graphics2D g, int x, int y, float size) {
        if (octagon == null) {
            octagon = new Polygon();
            octagon.addPoint(-3, -7); // 1
            octagon.addPoint(3, -7); // 2
            octagon.addPoint(7, -3); // 3
            octagon.addPoint(7, 3); // 4
            octagon.addPoint(3, 7); // 5
            octagon.addPoint(-3, 7); // 6
            octagon.addPoint(-7, 3); // 7
            octagon.addPoint(-7, -3); // 8
        }

        AffineTransform oldTransform = g.getTransform();
        g.transform(AffineTransform.getTranslateInstance(x, y));
        g.transform(AffineTransform.getScaleInstance(size / 14, size / 14));

        g.fill(octagon);

        g.setTransform(oldTransform);
    }
}

Related

  1. drawDottedRect(Graphics g, int x, int y, int w, int h)
  2. drawDropshipISPip(Graphics2D g2d, int width, int height, int circleSize, int fillCircleSize)
  3. drawEdge(Graphics g, int w, int h)
  4. drawEtchedRect(Graphics g, int x, int y, int width, int height, Color shadow, Color darkShadow, Color highlight, Color lightHighlight)
  5. drawFilledBox(Graphics2D g, int x, int y, int width, int height)
  6. drawFilter(Graphics g, Color c, double transparency, int midx, int midy, int rx, int ry)
  7. drawFleche1(Graphics g, double x, double y, double x1, double y1, int L)
  8. drawFocus(Graphics g, int x, int y, int w, int h)
  9. drawFocus(Graphics2D g2, int iX, int iY, int iWidth, int iHeight)