Java Example Program / Sample Source Code
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
public class LostOwnershipExample {
public static void main(String[] argv) throws Exception {
ClipboardOwner owner = new MyClipboardOwner();
StringSelection stringSelection = new StringSelection("String is here");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, owner);
}
}
class MyClipboardOwner implements ClipboardOwner {
// This method is called when object is lost the ownership
public void lostOwnership(Clipboard clipboard, Transferable contents) {
System.out.println("lost ownership");
}
} |
|
|