|
Code Samples Index
These code examples and other materials are subject to Sun Microsystems, Inc.
Legal Terms
Handling a Drop Event
The drop target in this example only accepts dropped String objects. A drop target must implement DropTargetListener and supply an implementation for drop().
public void drop(DropTargetDropEvent evt) {
try {
Transferable t = evt.getTransferable();
if (t.isDataFlavorSupported(
DataFlavor.stringFlavor)) {
evt.acceptDrop(
DnDConstants.ACTION_COPY_OR_MOVE);
String s = (String)t.getTransferData(
DataFlavor.stringFlavor);
evt.getDropTargetContext().dropComplete(true);
process(s);
} else {
evt.rejectDrop();
}
} catch (IOException e) {
evt.rejectDrop();
} catch (UnsupportedFlavorException e) {
evt.rejectDrop();
}
}
|
Examplets provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan.
Order this book from Amazon
|