开发者

mouse events on multiple polygons in java swing

开发者 https://www.devze.com 2023-03-10 12:20 出处:网络
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.

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 开发者_JAVA百科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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消