generate Rectangle2D - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

generate Rectangle2D

Demo Code

/**/* w  w  w .j a  v a  2  s.co  m*/
 * 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 generateRectangle(Point2D p1, Point2D p2) {
        double startX = Math.min(p1.getX(), p2.getX());
        double startY = Math.min(p1.getY(), p2.getY());
        double endX = Math.max(p1.getX(), p2.getX());
        double endY = Math.max(p1.getY(), p2.getY());

        return new Rectangle2D.Double(startX, startY, endX - startX, endY
                - startY);
    }
}

Related Tutorials