Here you can find the source of intersects(Rectangle rect1, Rectangle rect2, boolean vertical)
private static boolean intersects(Rectangle rect1, Rectangle rect2, boolean vertical)
//package com.java2s; /*/*from ww w .ja v a 2 s . com*/ GNU LESSER GENERAL PUBLIC LICENSE Copyright (C) 2006 The XAMJ Project This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Contact info: info@xamjwg.org */ import java.awt.*; public class Main { private static boolean intersects(Rectangle rect1, Rectangle rect2, boolean vertical) { if (vertical) { return !((rect1.y > rect2.y + rect2.height) || (rect2.y > rect1.y + rect1.height)); } else { return !((rect1.x > rect2.x + rect2.width) || (rect2.x > rect1.x + rect1.width)); } } }