get Rounded Rectangle - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

get Rounded Rectangle

Demo Code


//package com.java2s;

import java.awt.Shape;

import java.awt.geom.RoundRectangle2D;

public class Main {
    public static void main(String[] argv) throws Exception {
        double x = 2.45678;
        double y = 2.45678;
        double width = 2.45678;
        double height = 2.45678;
        System.out.println(getRoundedRectangle(x, y, width, height));
    }//  w  w w .j a v a 2 s.  c o  m

    static final double RADIUS = 7;
    static final float STROKE_WIDTH = 1f;

    static Shape getRoundedRectangle(double x, double y, double width,
            double height) {
        return getRoundedRectangle(x, y, width, height, STROKE_WIDTH);
    }

    static Shape getRoundedRectangle(double x, double y, double width,
            double height, float strokeWidth) {
        strokeWidth /= 2;
        RoundRectangle2D.Double roundRect = new RoundRectangle2D.Double(x
                + strokeWidth, y + strokeWidth, width - 2 * strokeWidth,
                height - 2 * strokeWidth, RADIUS, RADIUS);

        return roundRect;
    }
}

Related Tutorials