zoukankan      html  css  js  c++  java
  • e640. 使一个组件可拖动

    This example demonstrates the code needed to make a component draggable. The object being transferred in this example is a string.

        public class DraggableComponent extends JComponent
                implements DragGestureListener, DragSourceListener {
            DragSource dragSource;
        
            public DraggableComponent() {
                dragSource = new DragSource();
                dragSource.createDefaultDragGestureRecognizer(
                    this, DnDConstants.ACTION_COPY_OR_MOVE, this);
            }
            public void dragGestureRecognized(DragGestureEvent evt) {
                Transferable t = new StringSelection("aString");
                dragSource.startDrag (evt, DragSource.DefaultCopyDrop, t, this);
            }
            public void dragEnter(DragSourceDragEvent evt) {
                // Called when the user is dragging this drag source and enters
                // the drop target.
            }
            public void dragOver(DragSourceDragEvent evt) {
                // Called when the user is dragging this drag source and moves
                // over the drop target.
            }
            public void dragExit(DragSourceEvent evt) {
                // Called when the user is dragging this drag source and leaves
                // the drop target.
            }
            public void dropActionChanged(DragSourceDragEvent evt) {
                // Called when the user changes the drag action between copy or move.
            }
            public void dragDropEnd(DragSourceDropEvent evt) {
                // Called when the user finishes or cancels the drag operation.
            }
        }
    
    Related Examples
  • 相关阅读:
    简明Secure boot介绍
    密码学有什么用?
    mkimage, no such file or dir
    嵌入式系统安全简介
    希尔排序
    jQuery选择器
    css 选择器
    安装 SQL Server 2008 和管理工具 SQL Server 2008 management studio 及相关问题解决
    mac下安装安卓开发环境
    IOS开发小记-内存管理
  • 原文地址:https://www.cnblogs.com/borter/p/9575345.html
Copyright © 2011-2022 走看看