How to create an image map using Java Swing?

后端 未结 2 1808
猫巷女王i
猫巷女王i 2021-01-26 02:40

I need to make an image map using Swing that displays a background image, and then when the mouse hovers over (or clicks) specific hotspots, I need to pop up a \'zoomed-in\' ima

相关标签:
2条回答
  • 2021-01-26 03:17

    To listen to the mouse clicks implement the MouseListener interface, and add it to your panel. Then when the click is recieved you can use a JPopupMenu as you suggested, or you could even use a glass pane to show the zoomed in image.

    I'm guessing you want to achieve something similar to this post by Joshua Marinacci, he has also posted the source here, I would take a look at that.

    0 讨论(0)
  • 2021-01-26 03:18

    I would probably:

    • create some instance of Shape that represents each of your hotspots (could be a plain boring old Rectangle, or see GeneralPath if you need to create fancy shapes)
    • register a MouseListener which iterates through each of the Shapes and calls its contains() method to see if the clicked coordinate is inside the hotspot in question
    0 讨论(0)
提交回复
热议问题