I am wondering if there is an easier way to check if the mouse is in a rectangle. Currently I am using an if statement like so

if (mX > rectX && mX < rectX + 20 && mY > rectY && my < rectY + 10){
} // where mX is mouse X and mY is mouse Y and rectX is the rectangle x and rectY is the rectangle y and + 20 is the width and +10 is the height

This is very time consuming. I am wondering if there is a quicker way of doing this.

Thanks for your help.

No, that's really about it. You have to check against all four bounds for containment.

If you're using Rectangle to store the rectangles, you can use its contains() method, but it does pretty much the same calcs you are doing there.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.