GestureTest.java Source code

Java tutorial

Introduction

Here is the source code for GestureTest.java

Source

import java.awt.BorderLayout;
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.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;

public class GestureTest extends JFrame implements DragGestureListener {

    DragSource ds = new DragSource();

    String[] items = { "Java", "C", "C++", "Lisp", "Perl", "Python" };

    JList jl = new JList(items);

    public GestureTest() {
        super("Gesture Test");
        setSize(200, 150);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        getContentPane().add(new JScrollPane(jl), BorderLayout.CENTER);

        DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer(jl, DnDConstants.ACTION_COPY, this);
        setVisible(true);
    }

    public void dragGestureRecognized(DragGestureEvent dge) {
        System.out.println("Drag Gesture Recognized!");
    }

    public static void main(String args[]) {
        new GestureTest();
    }
}