Example usage for java.awt Rectangle createIntersection

List of usage examples for java.awt Rectangle createIntersection

Introduction

In this page you can find the example usage for java.awt Rectangle createIntersection.

Prototype

public Rectangle2D createIntersection(Rectangle2D r) 

Source Link

Usage

From source file:Main.java

private static float getPercentageOnScreen(Point location, Dimension size, Rectangle screen) {
    Rectangle frameBounds = new Rectangle(location, size);
    Rectangle2D intersection = frameBounds.createIntersection(screen);
    int frameArea = size.width * size.height;
    int intersectionArea = (int) (intersection.getWidth() * intersection.getHeight());
    float percentage = (float) intersectionArea / frameArea;
    return percentage < 0 ? 0 : percentage;
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(10, 10, 50, 40);

    System.out.println(r.createIntersection(new Rectangle(20, 20, 40, 40)));

    g2.fill(r);/* w  w w .  j av a  2  s  .  c  om*/
}