split Rectangle Vertically - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

split Rectangle Vertically

Demo Code


//package com.java2s;

import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Rectangle> splitVertically(Rectangle region) {
        List<Rectangle> list = new ArrayList<Rectangle>();
        int halfHeight = region.height / 2;
        list.add(new Rectangle(region.x, region.y, region.width, halfHeight));
        list.add(new Rectangle(region.x, region.y + halfHeight,
                region.width, region.height - halfHeight));
        return list;
    }/*from  w w w  .j  a v  a2s  . com*/
}

Related Tutorials