The JavaTM Tutorial

| Start of Tutorial > Start of Trail > Start of Lesson | Search

Trail: Drag and Drop

## A Drag and Drop Example by Sheetal Gupta

> ### About the example

> > This simple example contains two lists from which a user can drag and drop items from one list to another. It illustrates the concept that a `Component` can act as a "Drop Target" and as a "Drag Source." Here's a snapshot of this example:

> > The example uses `JList`, but any other `Component` could easily replace `JList`. All you would have to do is revise implementations of the `DNDComponentInterface` methods.

> ### About the files

> > - `DNDList.java`: the specialized `JList` which can behave as a `DropTarget` and as a `DragSource`.
> > - `DNDComponentInterface.java`: the interface that all components must implement to add/remove elements to itself and to detect when a drop/drag occurs.
> > - `TestDND.java`: the tester for this class.

> ### Running this example

> > To run this example, do the following using JDK 1.2:
> > 1. `javac DNDList.java`
> > 2. `javac DNDComponentInterface.java`
> > 3. `javac TestDND.java`
> > 4. `java TestDND`

> ### About the Author

> > Sheetal Gupta is a Senior Consultant with Ernst and Young's Java Service Line, based in New York.

| Start of Tutorial > Start of Trail > Start of Lesson | Search