Drag and Drop

In the latest version of the SDK, all drag-and-drop (DnD) operations (for both Swing and AWT components) are supported through the interface java.awt.dnd. Listing 37.14 shows a typical DnD program.

Note

When a class implements an interface, the class must provide an implementation of every method in the interface. To implement a drag-and-drop target, a class must implement DropTargetListener. As shown in Listing 37.14, most of the work is done in dragEnter() and drop().

Code Listing 37.14. DnDTest.java—An Implementation of a DropTargetListener
 import java.awt.*; import java.awt.dnd.*; import java.awt.datatransfer.*; import java.awt.event.*; import java.io.*; public class DnDTest extends Frame implements DropTargetListener { DropTarget ...

Get Platinum Edition Using XHTML™, XML, and Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.