Here you can find the source of intersection(Rectangle rectangle, Rectangle rectangle1, Rectangle rectangle2)
public static void intersection(Rectangle rectangle, Rectangle rectangle1, Rectangle rectangle2)
//package com.java2s; //License from project: Apache License import java.awt.Rectangle; public class Main { public static void intersection(Rectangle rectangle, Rectangle rectangle1, Rectangle rectangle2) { int i = rectangle.x; int j = rectangle.y; int k = rectangle1.x; int l = rectangle1.y; int i1 = i; i1 += rectangle.width;/*w w w.j a v a 2 s.c o m*/ int j1 = j; j1 += rectangle.height; int k1 = k; k1 += rectangle1.width; int l1 = l; l1 += rectangle1.height; if (i < k) i = k; if (j < l) j = l; if (i1 > k1) i1 = k1; if (j1 > l1) j1 = l1; i1 -= i; j1 -= j; if (i1 < 0x80000000) i1 = 0x80000000; if (j1 < 0x80000000) j1 = 0x80000000; rectangle2.setBounds(i, j, i1, j1); } }