?? dragjlabel.java~1~
字號:
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."); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -