I've got a little problem and I'd like to seek your advice on it. I have a few circles (Ellipse2D.Float) drawn to a JPanel. Those circles should change their size/color when the mouse hovers over them or the player clicks on them, but I can not figure out how to implement it.

All the circles have their fixed location while the panel's dimension is also fixed at 600*600.

I've tried two things so far, my first idea was to use MouseInfo's getPointerInfo() to check if any circle contains the current location of the cursor, but I don't really like that solution. I also tried to create a custom event, but I had never done it before and I couldn't make it to work.

The solution you mentioned is exactly the same what I did, but I didn't really liked it. For example if I have 200 circles I have to loop through them in every game loop, which doesn't seems like a correct solution for me. I was thinking about something like MouseListener's mouseEntered() method used on a JPanel where the cursor's location triggers the event by hovering over the panel, but I could't make it work as I wanted.

If I do this brute-force check every time, should I divide the panel into smaller rectangles, like 3 600*200 pieces, check the cursor position against them first and then do the check on the circles that are in those pieces? Or it would be pointless?

Imagine a GUI with some buttons on it, where you would like to check if the user clicks on any of them (or highlight them if the cursor hovers over them). Would you do it this way? Just doesn't seems right.

I'm sorry if I was unclear. I'd like those circles (shapes) to act like, lets say a JToggleButton which has 3 states based on mouse interact (idle, mouse over and pressed). Despite the fact that I have only 24 circles here, I'd like to work out a solution which can be applied to more of them, without the need of looping through an array/list with hundreds of elements every time. A circle is defined as a class.

I'm kind of new to game developement (as you might have noticed ), I do not know things in concepts, that is why I wrote every time that I don't like the solution.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org