Per the title, I'm trying to figure out a way to restrict the boundaries of mouseClicked.

I have an image that moves across the screen. When I click on it, it alternates with another image. However, I only want it to alternate when I click within 30 pixels of its current location.

Now I've been trying out event.getX() and event.getY() methods for where I click, and the picture's current location using relational operators and conditional statments.

Is there an easier way to go about this?

Recommended Answers

All 3 Replies

Is there an easier way to go about this?

Probably not.

Alright, I was just curious. It's working though. Thank you.

why not, this is simple and possible, you can put there GlassPane, could be layed and possitioning by every Layoutmanagers, notice GlassPane can consume only MouseEvents,

Be a part of the DaniWeb community

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