• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tracking Multiple Objects

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Foley Ma wrote: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?



Yes. In fact you would have to do that even if you only had two objects.
 
Foley Ma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I suspected. Thank you!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic