List of usage examples for java.awt Rectangle createIntersection
public Rectangle2D createIntersection(Rectangle2D r)
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*/ }