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 loaded when I click on them so I can drag them around the screen.
Any ideas?
If you use a
JLabelfor each image, and make theJLabelssubcomponents of theJPanel, it’ll automatically draw the image, and you can addMouseListeners to each of them to be able to drag them around the screen.