Java Example Program/ Sample Source Code
import java.awt.BorderLayout;
import java.awt.List;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class SetSourceActions_DragGestureRecognizer extends JFrame implements
DragGestureListener, DragSourceListener {
DragSource dataSource;
List list;
public SetSourceActions_DragGestureRecognizer() {
super("SetSourceActions_DragGestureRecognizer");
setSize(200, 150);
list = new List(2);
list.add("Java");
list.add("Jsp");
list.add("Servlet");
JScrollPane scrollPane = new JScrollPane(list);
getContentPane().add(scrollPane, BorderLayout.CENTER);
dataSource = new DragSource();
DragGestureRecognizer dgr = dataSource
.createDefaultDragGestureRecognizer(list,
DnDConstants.ACTION_COPY, this);
dgr.setSourceActions(1);
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
}
public void dragGestureRecognized(DragGestureEvent dge) {
System.out.println("DragGestureEvent Fired");
}
public static void main(String args[]) {
new SetSourceActions_DragGestureRecognizer();
}
@Override
public void dragDropEnd(DragSourceDropEvent arg0) {
System.out.println("DragSourceDropEvent Fired");
}
@Override
public void dragEnter(DragSourceDragEvent arg0) {
System.out.println("DragSourceDropEvent Fired");
}
@Override
public void dragExit(DragSourceEvent arg0) {
System.out.println("DragSourceDropEvent Fired");
}
@Override
public void dragOver(DragSourceDragEvent arg0) {
System.out.println("DragSourceDropEvent Fired");
}
@Override
public void dropActionChanged(DragSourceDragEvent arg0) {
System.out.println("DragSourceDropEvent Fired");
}
} |
|
|