import java.awt.Point;
import java.awt.MouseInfo;

java.awt.Insets insets;
Point mouse, win;

void setup() {
  size(400, 400);
  frame.pack();
  smooth();
}

void draw() {
  setFrame();
  if(insideFrame()) {
    background(95);
  } 
  else {
   background(0); 
  }  
}

//set position of frame
void setFrame() 
{  
  mouse = MouseInfo.getPointerInfo().getLocation();
  win = frame.getLocation();

  if(!frame.isUndecorated()){
    //add borders of window
    insets = frame.getInsets();
    win.x += insets.left;
    win.y += insets.top;
  }
}

boolean insideFrame() {
  boolean in = false;
  if(mouse.x-win.x >= 0 && width >= mouse.x-win.x)
    if(mouse.y-win.y >= 0 && height >= mouse.y-win.y)
      in = true;

  return in;
}