Java Example Program/ Sample Source Code
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.List;
import java.awt.Point;
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.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class GetDragActionExample extends JFrame implements DragGestureListener {
DragSource dataSource;
List list;
public GetDragActionExample() {
super("DragGestureEventExample");
setSize(200, 150);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
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);
setVisible(true);
}
public void dragGestureRecognized(DragGestureEvent dge) {
Point dragOrigin = dge.getDragOrigin();
Component component2 = dge.getComponent();
int dragAction = dge.getDragAction();
DragSource dragSource = dge.getDragSource();
DragGestureRecognizer sourceAsDragGestureRecognizer = dge
.getSourceAsDragGestureRecognizer();
InputEvent triggerEvent = dge.getTriggerEvent();
}
public static void main(String args[]) {
new GetDragActionExample();
}
} |
|
|