There a number of ways you can approach this.
If you are using separate components for the source images and drop target then you can take
advantage of the Swing built–in drag and drop system. This is explained with examples in the
tutorial page
Introduction to Drag and Drop and Data Transfer. See the section
Data Transfer with a Custom Component. This is a general–purpose system and takes a
while to put together.
If you are doing all the dragging and dropping in a single component then things can be
greatly simplified. You have the option to use components or a graphics approach.
With components you mount the images in JLabels with ImageIcons, set the parent containers
layout to null, add the labels and call
setBounds for each one. Use the
setBounds method to reposition the labels with your mouse code.
For the graphics approach you can use some Rectangles to both locate the images for drawing
and for detecting mouse selections (hit–
testing) for dragging. I made up a small example of
this last option.
Image files are from the
Examples Index, down low.