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 GetComponent_DragGestureRecognizer extends JFrame implements
DragGestureListener, DragSourceListener {
DragSource dataSource;
List list;
public GetComponent_DragGestureRecognizer() {
super("GetComponent_DragGestureRecognizer");
setSize(200, 150);
list = new List(2);
list.add("Java");
list.add("Jsp");
list.add("Servlet");
getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);
dataSource = new DragSource();
DragGestureRecognizer dgr = dataSource
.createDefaultDragGestureRecognizer(list,
DnDConstants.ACTION_COPY, this);
System.out.println(dgr.getComponent());
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 GetComponent_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");
}
} |
|
|