Topic: 想通过拖拉鼠标取得地址,有办法吗?

  Print this page

1.想通过拖拉鼠标取得地址,有办法吗? Copy to clipboard
Posted by: woodworm
Posted on: 2004-03-09 20:58

好比在ie里面,通过拖拉鼠标,取得当前正在浏览的网页的地址,放入我的java界面的软件里。
实在不行,用快捷键也可以。有什么办法可以实现,请高人指教

2.Re:想通过拖拉鼠标取得地址,有办法吗? [Re: woodworm] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-10 12:51

import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.io.IOException;
import java.util.List;
import javax.swing.*;
/**
* @author Jove
*/
public class DndFrame extends JFrame implements DropTargetListener {
  public static void main(String[] args) {
    new DndFrame().show();
  }
  private JLabel label;
  private DndFrame() {
    super("Test Drag and drop test");
    setBounds(100, 100, 400, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    new DropTarget(this, this);
    getContentPane().add(label = new JLabel());
  }
  public void dragEnter(DropTargetDragEvent dtde) {}
  public void dragExit(DropTargetEvent dte) {}
  public void dragOver(DropTargetDragEvent dtde) {}
  public void drop(DropTargetDropEvent evt) {
    Transferable t = evt.getTransferable();
    if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
      try {
        List fileList =
          (List) t.getTransferData(DataFlavor.javaFileListFlavor);
        String s = fileList.toString();
        label.setText(s);
      } catch (UnsupportedFlavorException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
      try {
        String s = (String) t.getTransferData(DataFlavor.stringFlavor);
        label.setText(s);
      } catch (UnsupportedFlavorException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else {
      evt.rejectDrop();
    }
  }
  public void dropActionChanged(DropTargetDragEvent dtde) {}
}

3.Re:想通过拖拉鼠标取得地址,有办法吗? [Re: woodworm] Copy to clipboard
Posted by: Lomone
Posted on: 2004-03-10 21:38

good jove
support it

4.Re:想通过拖拉鼠标取得地址,有办法吗? [Re: woodworm] Copy to clipboard
Posted by: zzj
Posted on: 2004-03-11 10:02

It's very cool!! Smile

5.Re:想通过拖拉鼠标取得地址,有办法吗? [Re: woodworm] Copy to clipboard
Posted by: caoyi
Posted on: 2004-03-11 21:13

好玩。。。。研究一下。。。(正好在作下载相关程序。。。。。)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923