⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dragjlabel.java

📁 java实现的鼠标拖放的实现
💻 JAVA
字号:
package jdraganddropdemo;import javax.swing.JLabel;import java.awt.dnd.DragGestureEvent;import java.awt.dnd.DragGestureListener;import java.awt.dnd.*;import java.awt.datatransfer.*;class DragJLabel extends JLabel implements DragGestureListener, DragSourceListener {  DragSource ds = DragSource.getDefaultDragSource();  public DragJLabel(String title,int alignment){    super(title,alignment);    int action = DnDConstants.ACTION_COPY_OR_MOVE;    ds.createDefaultDragGestureRecognizer(this,action,this);  }  public void dragGestureRecognized(DragGestureEvent dge) {    /**@todo Implement this java.awt.dnd.DragGestureListener method*/    //throw new java.lang.UnsupportedOperationException("Method dragGestureRecognized() not yet implemented.");    try{      Transferable tr = new StringSelection(this.getText());      dge.startDrag(DragSource.DefaultCopyNoDrop,tr,this);    }catch(Exception err){      err.printStackTrace();    }  }  public void dragEnter(DragSourceDragEvent dsde) {    /**@todo Implement this java.awt.dnd.DragSourceListener method*/    //throw new java.lang.UnsupportedOperationException("Method dragEnter() not yet implemented.");    DragSourceContext dsc = dsde.getDragSourceContext();    int action = dsde.getDropAction();    if ((action&DnDConstants.ACTION_COPY)!=0)      dsc.setCursor(DragSource.DefaultCopyDrop);    else      dsc.setCursor(DragSource.DefaultCopyNoDrop);  }  public void dragOver(DragSourceDragEvent dsde) {    /**@todo Implement this java.awt.dnd.DragSourceListener method*/    //throw new java.lang.UnsupportedOperationException("Method dragOver() not yet implemented.");  }  public void dropActionChanged(DragSourceDragEvent dsde) {    /**@todo Implement this java.awt.dnd.DragSourceListener method*/    //throw new java.lang.UnsupportedOperationException("Method dropActionChanged() not yet implemented.");  }  public void dragExit(DragSourceEvent dse) {    /**@todo Implement this java.awt.dnd.DragSourceListener method*/    //throw new java.lang.UnsupportedOperationException("Method dragExit() not yet implemented.");  }  public void dragDropEnd(DragSourceDropEvent dsde) {    /**@todo Implement this java.awt.dnd.DragSourceListener method*/    //throw new java.lang.UnsupportedOperationException("Method dragDropEnd() not yet implemented.");    if (!dsde.getDropSuccess())      return;   // int action = dsde.getDropAction();    //if ((action&DnDConstants.ACTION_MOVE)!=0)     // this.setText("");  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -