1

i am trying to write a code for my task. my task is, i have draw may polygons on a single panel by giving coordinate values. and aplly mouse moved event to those polygons.

my problem is i can draw all polygons but don't know how to apply mousemoved event to all tha polygons.(i.e when i move my mouse to particular polygon the background color of that particual polygon should change, and when i exit it should go back to normal stage).

i can do all this manually for one or two polygons. but in my scenario i'll have so many polygons. i can't write individually for each.

so please help me regarding this issue.

thanks.

ran
  • 667
  • 4
  • 9
  • 16

1 Answers1

2

This example show how to solve the problem for one Polygon. Note that mouseMoved() merely records the current mouse Point. In response to repaint(), paintComponent() makes a check using contains(). For multiple polygons, you would simply iterate over a List<Polygon>, checking each in turn.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045