split Rectangle Horizontally - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

split Rectangle Horizontally

Demo Code


//package com.java2s;

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

public class Main {
    public static List<Rectangle> splitHorizontally(Rectangle region) {
        List<Rectangle> list = new ArrayList<Rectangle>();
        int halfWidth = region.width / 2;
        list.add(new Rectangle(region.x, region.y, halfWidth, region.height));
        list.add(new Rectangle(region.x + halfWidth, region.y, region.width
                - halfWidth, region.height));
        return list;
    }//  w  ww  .j  a  v  a  2 s . c  o  m
}

Related Tutorials