Sensing when the mouse is inside a rectangle with Processing

int buttonSize = 100;

void setup()
{
size(300, 300);
}

void draw()
{
button(0, 0, buttonSize, buttonSize); // top left
button(width - buttonSize, 0, buttonSize, buttonSize); // top right
button(0, height - buttonSize, buttonSize, buttonSize); // top right
button(width - buttonSize, height - buttonSize, buttonSize, buttonSize); // top right
}

void button( int x, int y, int w, int h )
{
// if mouse is inside rectangle
if ( mouseX >= x && mouseX <= x+w &&
mouseY >= y && mouseY <= y+h) {

if (mousePressed) {
fill(255, 0, 0); // the color if the mouse is pressed and over the button
}
else {
fill(255, 255, 0); // the color if the mouse is over the button
}

}
else {
fill(0, 0, 255); // the color if the mouse is not over the button
}

rect(x, y, w, h);
}