0

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?

BenJacob
  • 957
  • 10
  • 31
  • Check this [How to get location of a mouse click relative to a swing window](http://stackoverflow.com/questions/12396066/how-to-get-location-of-a-mouse-click-relative-to-a-swing-window) – Neeraj Jain Mar 10 '15 at 14:34

1 Answers1

2

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.

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79