FileDocCategorySizeDatePackage
DragTest.javaAPI DocExample2044Thu Oct 24 20:14:28 BST 2002None

DragTest

public class DragTest extends JFrame implements DragGestureListener, DragSourceListener

Fields Summary
DragSource
ds
JList
jl
StringSelection
transferable
String[]
items
Constructors Summary
public DragTest()


    
    super("Drag Test");
    setSize(200,150);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
        System.exit(0);
      }
    });
    jl = new JList(items);
    jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER);

    ds = new DragSource();
    DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(
			  jl, DnDConstants.ACTION_COPY, this);
    setVisible(true);
  
Methods Summary
public voiddragDropEnd(java.awt.dnd.DragSourceDropEvent dsde)

    System.out.print("Drag Drop End: ");
    if (dsde.getDropSuccess()) {
      System.out.println("Succeeded");
    }
    else {
      System.out.println("Failed");
    }
  
public voiddragEnter(java.awt.dnd.DragSourceDragEvent dsde)

    System.out.println("Drag Enter");
  
public voiddragExit(java.awt.dnd.DragSourceEvent dse)

    System.out.println("Drag Exit");
  
public voiddragGestureRecognized(java.awt.dnd.DragGestureEvent dge)

    System.out.println("Drag Gesture Recognized!");
    transferable = new StringSelection(jl.getSelectedValue().toString());
    ds.startDrag(dge, DragSource.DefaultCopyDrop, transferable, this);
  
public voiddragOver(java.awt.dnd.DragSourceDragEvent dsde)

    System.out.println("Drag Over");
  
public voiddropActionChanged(java.awt.dnd.DragSourceDragEvent dsde)

    System.out.println("Drop Action Changed");
  
public static voidmain(java.lang.String[] args)

    new DragTest();