Reputation: 987
I am using Java with Swing and I want to detect mouse clicks at a number of locations (~200) in the view.
Should I use coordinates to ascertain where the click occurs (requiring searching through every location) or add multiple JPanels over each location and listen for mouse events for all of them?
Upvotes: 0
Views: 64
Reputation: 31299
If you have a great number of points, you can use a QuadTree datastructure to efficiently search through all points with a two-dimensional area as the search key. Although QuadTrees are not in the standard Java API, there are several Java implementations that you can easily find on the Internet.
Upvotes: 2