Start of Tutorial > Start of Trail > Start of Lesson | Search |
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 aComponent
can act as a "Drop Target" and as a "Drag Source." Here's a snapshot of this example:The example uses JList
, but any otherComponent
could easily replaceJList
. All you would have to do is revise implementations of theDNDComponentInterface
methods.About the files
DNDList.java
: the specializedJList
which can behave as aDropTarget
and as aDragSource
.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:
javac DNDList.java
javac DNDComponentInterface.java
javac TestDND.java
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 |