Hello,
I could find lots of tutorials on drawing and interacting with a single graphical object, but not when you have several objects, so any help would be greatly appreciated.
I have a JPanel that draws many text, lines, and circles all over the screen. I use TextLayout, Lines2D, and Ellipse2D to place the objects on the JPanel. I want the objects to be interactive and listen to events. For example, when a user clicks on a
string I want additional information to pop up that pertains to that string.
My question is, when a user clicks on the object, how do I know which object it clicks on? I create a TextLayout for each text. Is this the wrong approach? Every tutorial I read has one textlayout and check for hittests against the text layout. But those tutorial also only displays one string. Similar graphics tutorial I read can erase and redraw an object, because that is the only object they have on the screen.
But when I have tens of objects, how do I know exactly which object was clicked on? Would I have to look through each object and check for hit
test? Thanks!