Here you can find the source of intersects(final Rectangle elementRect, final Rectangle viewportRect)
private static boolean intersects(final Rectangle elementRect, final Rectangle viewportRect)
//package com.java2s; import java.awt.*; public class Main { private static boolean intersects(final Rectangle elementRect, final Rectangle viewportRect) { // check the location of the top of the element if ((elementRect.y < viewportRect.y) || (elementRect.y > viewportRect.y + viewportRect.height)) { return false; }//from www. j a v a 2 s . c om // check the location of the bottom of the element if ((elementRect.y + elementRect.height < viewportRect.y) || (elementRect.y + elementRect.height > viewportRect.y + viewportRect.height)) { return false; } return true; } }