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.DragSource;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Arrays;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class ToArray_DragGestureEvent extends JFrame implements
DragGestureListener {
DragSource dataSource;
List list;
public ToArray_DragGestureEvent() {
super("DnDConstantsExample ");
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();
dataSource.createDefaultDragGestureRecognizer(list,
DnDConstants.ACTION_COPY, this);
setVisible(true);
}
public void dragGestureRecognized(DragGestureEvent dge) {
System.out.println("DragGestureEvent Fired"
+ Arrays.toString(dge.toArray()));
}
public static void main(String args[]) {
new ToArray_DragGestureEvent();
}
} |
|
|