How to find if image is clicked in JApplet?

半城伤御伤魂 提交于 2019-12-02 07:13:20

问题


It is to support image dragging. How to find if an image is clicked in JApplet?

I'm sure there is an easy way to do this, but I've looked everywhere and cannot seem to find it.


回答1:


Options:

  • Use a JLabel to hold the image, and give it a MouseListener. Simple.
  • Or create a JButtton and use the Image as the button's ImageIcon. Probably simpler.



回答2:


See the Drag and Drop and Data Transfer lesson of the tutorial.

If the purpose of the dragging is to change the order in a slideshow or similar, look to a JList. See setDragEnabled(true) & How to Use Lists for more details.

For the display component, I would recommend a JLabel as suggested by @Hover. JList uses a JLabel as the rendering component by default.



来源:https://stackoverflow.com/questions/10543745/how-to-find-if-image-is-clicked-in-japplet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!