问题
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