This example uses several of the classes found in the
java.awt.dnd package. Here’s how they fit
together (see Figure 24-3).
Remember that we’re just looking at the drop side of DnD. We’ll explore
the drag side in the next section and autoscrolling at the end of this
Figure 24-3. DnD class diagram for the drop side
An obvious starting point for playing with this API is
DropTarget class. This class
encapsulates the functionality you add to regular GUI components so
that they can respond to drop events. You can make just about anything
a drop target. Well, not anything, but any
Component can be a drop target.
Typically, you pick the component that responds to the drop—such as
the text area in our example—but you can also pick a proxy component
that simply helps produce all the right events while your event
handler plays with the dropped data.
Note that just because the
DropTarget class implements the
DropTargetListener interface, this does not
mean that the target is already handling drop events for you. The
DropTarget class implementation of
the interface supports the internal mechanisms for responding to
events; it isn’t used by us as programmers. We still have to create
our own listener.
Table 24-4 lists
five properties of the
class that govern the context of this target and its data transfer
Table 24-4. DropTarget ...