Convert Rectangle2D to Rectangle - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

Convert Rectangle2D to Rectangle

Demo Code


//package com.java2s;

import java.awt.Rectangle;

import java.awt.geom.Rectangle2D;

public class Main {
    public static Rectangle toRectangle(Rectangle2D b) {
        if (b == null) {
            return null;
        }/*from w ww . j a  va 2s . c o  m*/
        if (b instanceof Rectangle) {
            return (Rectangle) b;
        } else {
            return new Rectangle((int) b.getX(), (int) b.getY(),
                    (int) b.getWidth(), (int) b.getHeight());
        }
    }
}

Related Tutorials