Here you can find the source of getPercentageOnScreen(Point location, Dimension size, Rectangle screen)
private static float getPercentageOnScreen(Point location, Dimension size, Rectangle screen)
//package com.java2s; //License from project: Apache License import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Rectangle2D; public class Main { 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 w w w. j av a 2 s .c o m }