Select an image from JPanel
I am working on a small project which requires me to load images into a window and then move them around at will.
Thus far I can load images onto a JPanel simply by using a graphics object to draw them to the JPanel.
Now I'm faced with the challenge of figuring out how to differentiate between the various images I've loade开发者_运维问答d when I click on them so I can drag them around the screen.
Any ideas?
If you use a JLabel
for each image, and make the JLabels
subcomponents of the JPanel
, it'll automatically draw the image, and you can add MouseListener
s to each of them to be able to drag them around the screen.
Use the Component Mover to drag any component around the screen.
精彩评论