generate Centered Rectangle - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

generate Centered Rectangle

Demo Code

/**/*from   w  w w .j a  v a 2s .  c om*/
 * Copyright Tao, All Rights Reserved.
 * Confidential, do not distribute.
 *
 * Any source code displaying this header must
 * be considered closed source and confidential
 * until the project is released under an open
 * source license.
 */
//package com.java2s;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class Main {
    public static Rectangle2D generateCenteredRectangle(Point2D center,
            double width, double height) {
        double startX = center.getX() - width / 2;
        double startY = center.getY() - height / 2;

        return new Rectangle2D.Double(startX, startY, width, height);
    }
}

Related Tutorials