Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:java中能不能监视粘贴板?? [Re:tomh2004]
tomh2004





发贴: 14
积分: 0
于 2004-09-17 15:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ok,谢谢!
/**
* AWT Sample application
*
* @author
* @version 1.00 04/09/16
*
*/
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.Toolkit;
import java.io.*;
class MyClipboardOwner implements ClipboardOwner{
  public void lostOwnership(Clipboard clipboard,Transferable contents)
  {
  }
  public static String getClipboard() {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

try {
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String text = (String)t.getTransferData(DataFlavor.stringFlavor);
return text;
}
} catch (UnsupportedFlavorException e) {
} catch (IOException e) {
}
return null;
}

}
public class Hello {

public static void main(String[] args) {
ClipboardOwner owner=new MyClipboardOwner();
StringSelection ss=new StringSelection("A String");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss,owner);
System.out.println(owner.getClipboard());
}
}




JBuilder使用技巧

话题树型展开
人气 标题 作者 字数 发贴时间
6844 java中能不能监视粘贴板?? tomh2004 29 2004-09-16 23:08
5851 Re:java中能不能监视粘贴板?? yamakasy 12 2004-09-16 23:51
5950 Re:java中能不能监视粘贴板?? tomh2004 12 2004-09-17 08:46
5816 Re:java中能不能监视粘贴板?? yamakasy 52 2004-09-17 10:06
6058 Re:java中能不能监视粘贴板?? tomh2004 1376 2004-09-17 15:49
5985 Re:java中能不能监视粘贴板?? ghuang 42 2004-09-18 13:19
5987 Re:java中能不能监视粘贴板?? tomh2004 23 2004-09-18 21:37
6179 Re:java中能不能监视粘贴板?? littledeer1974 26 2004-09-19 10:03

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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