accessing clipboard

i want to make application to handel any changed of data occur in clipboard but the problem is that the class Clipboard handel only the changed of type of DataFlavor .My questions are :First i want to understand in depth the mechanism of event and event object whish are the source of notification ,so i want if there are an article which talk in depth about event.

My second question is how i can change the Clipboard class in jre /lib and the jvm will use it as the Clipboard class.

Thanks .

[512 byte] By [kim2507a] at [2007-11-27 4:42:03]
# 1

Event:

http://java.sun.com/docs/books/tutorial/uiswing/events/index.html

Clipboard changes listener:

When an item is set on the system clipboard, it is possible to be notified when that item is no longer on the clipboard. This is done by including a clipboard owner object when setting the item.

// This class serves as the clipboard owner.

class MyClipboardOwner implements ClipboardOwner {

// This method is called when this object is no longer

// the owner of the item on the system clipboard.

public void lostOwnership(Clipboard clipboard, Transferable contents) {

//see getting clipboard content

}

}

Here's some code that uses the clipboard owner:

// Create a clipboard owner

ClipboardOwner owner = new MyClipboardOwner();

// Set a string on the system clipboard and include the owner object

StringSelection ss = new StringSelection("A String");

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, owner);

Getting clipboard content:

This examples defines methods for getting and setting text on the system clipboard.

// If a string is on the system clipboard, this method returns it;

// otherwise it returns null.

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;

}

// This method writes a string to the system clipboard.

// otherwise it returns null.

public static void setClipboard(String str) {

StringSelection ss = new StringSelection(str);

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

}

java_2006a at 2007-7-12 9:53:35 > top of Java-index,Desktop,Runtime Environment...