Just a little snippet of code for getting accurate mouse coordinates within a JFrame.
It sets it to either 0 or frame.width/height if its out of bounds
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
mx = (int) b.getX() - frame.getX();
my = (int) b.getY() - frame.getY();
if (mx < 0) {
mx = 0;
}
if (my < 0) {
my = 0;
}
if (mx > WIDTH) {
mx = 0;
}
if (my > HEIGHT) {
my = 0;
}