用JAVA搞这个不好办
呵呵,也不是很不好搞哦
下面是个简单的示例程序,功能虽不强,足以说明问题了.
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.*;
import java.awt.dnd.*;
import java.io.*;
import java.util.*;
import javax.swing.*;/**
*一个简单的拖放示例程序
*将文件或文件夹拖放到文本区然后放下,就会显示这些文件的一些信息
*@author Eastsun
*@version .1 2006/12/24
*/
public class ShowMsg{
public static void main(String[] args){
new DropTargetFrame();
}
}class DropTargetFrame extends JFrame{
public DropTargetFrame(){
super(\"文件信息\");JTextArea textArea = new JTextArea(\"@@@@@@@@@@将文件拖放到编辑区@@@@@@@@@@@@\n By Eastsun\n\");
JScrollPane scrollPane =new JScrollPane(textArea);
textArea.setLineWrap(true);
textArea.setEditable(false);
add(scrollPane);
new DropTarget(textArea, new TextDropTargetListener(textArea));
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 300;
}class TextDropTargetListener extends DropTargetAdapter{
public TextDropTargetListener(JTextArea aTextArea){
textArea = aTextArea;
}
public void drop(DropTargetDropEvent event){
event.acceptDrop(DnDConstants.ACTION_COPY);
Transferable transferable = event.getTransferable();DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++){
DataFlavor d = flavors[i];try{
if (d.equals(DataFlavor.javaFileListFlavor)){
java.util.List<File> fileList
= (java.util.List<File>) transferable.getTransferData(d);
for (File f : fileList){
textArea.append(\"文件名: \"+f + \"\n\");
textArea.append(\"文件属性: \");
String value=null;
if(f.isFile())
value =\"文件, 文件大小: \"+f.length()+\"bytes\";
else if(f.isDirectory())
value =\"文件夹\";
else
value =\"未知\";
textArea.append(value+\"\n\");
}
}
}
catch (Exception e){
textArea.append(e + \"\n\");
}
}
textArea.append(\"\n\");
event.dropComplete(true);
}
private JTextArea textArea;
}
[此贴子已经被作者于2006-12-24 16:26:56编辑过]