?? draglist.java
字號:
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import javax.swing.*;
public class DragList extends JList implements DragGestureListener, DragSourceListener{
DragSource dragSource=DragSource.getDefaultDragSource(); //拖動源
public DragList(Object[] data){ //構造函數
super(data);
int action = DnDConstants.ACTION_COPY_OR_MOVE; //拖動類型
dragSource.createDefaultDragGestureRecognizer(this,action,this); //創建拖動識別
}
public void dragGestureRecognized(DragGestureEvent dge) {
try{
Transferable trans = new StringSelection(this.getSelectedValue().toString()); //得到拖動的Transferable對象
dge.startDrag(DragSource.DefaultCopyNoDrop,trans,this); //開始拖動操作
}catch(Exception err){
err.printStackTrace(); //輸出錯誤信息
}
}
public void dragEnter(DragSourceDragEvent dragSourcede) { //拖動進入處理
DragSourceContext dragSourceContext = dragSourcede.getDragSourceContext(); //得到拖動上下文對象
int action = dragSourcede.getDropAction(); //得到拖動命令
if ((action&DnDConstants.ACTION_COPY)!=0) //判斷命令類型
dragSourceContext.setCursor(DragSource.DefaultCopyDrop); //設置光標類型
else
dragSourceContext.setCursor(DragSource.DefaultCopyNoDrop);
}
public void dragOver(DragSourceDragEvent dragSourcede) {
}
public void dropActionChanged(DragSourceDragEvent dragSourcede) {
}
public void dragExit(DragSourceEvent dragSourcee) {
}
public void dragDropEnd(DragSourceDropEvent dragSourcede) {
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -