O'Reilly logo

Platinum Edition Using XHTML™, XML, and Java™ 2 by Andrew H. Watt, Mike Morgan, Jim O'Donnell, Eric Ladd

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required