Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

To exchange data with other (native ! ) programs we use java.awt.datatransfer.Clipboard .

Try to get access by asking our link to the platform : java.lang.Toolkit .

If the 'From' button is pressed, we take a look to see what's on the clipboard.

If we get a valid reference, we ask it for a String representation of the data.

If that's available, getTransferData returns it as an Object reference, so we cast it to String.

If it's not present, getTransferData throws an UnsupportedFlavorException, that will be caught.

If the 'To' button is clicked, we make a java.awt.datatransfer.StringSelection .

And place it on the clipboard.

If another process replaces what's on the clipboard,......

.... our lostOwnership method is called,.....

....which is our implementation of the ClipboardOwner interface.

In it we show what data formats the clipboard now has to offer.

==========

NOTES

==========

A regular applet can't do this, for security reasons, unless you can tweak the browser to allow clipboard access or use a code-signing technique as explained in our Advanced Lessons.

A stand-alone application has no problems with it.

.