round Filled Rectangle - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

round Filled Rectangle

Demo Code


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

public class Main {
    public static void roundFilledRectangle(Graphics g, int x1, int y1,
            int x2, int y2, int rtl, int rtr, int rbl, int rbr) {
        // top left edge
        g.fillArc(x1, y1, 2 * rtl, 2 * rtl, 90, 90);

        // top right edge
        g.fillArc(x2 - 2 * rtr, y1, 2 * rtr, 2 * rtr, 0, 90);

        // bottom left edge
        g.fillArc(x1, y2 - 2 * rbl, 2 * rbl, 2 * rbl, 180, 90);

        // bottom right edge
        g.fillArc(x2 - 2 * rbr, y2 - 2 * rbr, 2 * rbr, 2 * rbr, 270, 90);

        ////from   ww  w  .j  a  v a 2  s .  co  m
        Polygon p = new Polygon();
        p.addPoint(x1, y1 + rtl);
        p.addPoint(x1 + rtl, y1 + rtl);
        p.addPoint(x1 + rtl, y1);
        p.addPoint(x2 - rtr, y1);
        p.addPoint(x2 - rtr, y1 + rtr);
        p.addPoint(x2, y1 + rtr);
        p.addPoint(x2, y2 - rbr);
        p.addPoint(x2 - rbr, y2 - rbr);
        p.addPoint(x2 - rbr, y2);
        p.addPoint(x1 + rbl, y2);
        p.addPoint(x1 + rbl, y2 - rbl);
        p.addPoint(x1, y2 - rbl);

        g.fillPolygon(p);
    }
}

Related Tutorials