Start Search Contents Index Links About

Bookmark utility part 3

Drag & Drop out

2002 - Week 9 - Havard Rast Blok

As I said two weeks ago, we will try do develop a bookmark utility. Thus it would be necessary to not only receive drop objects, but also send some. This week we will make our application the source of the drag and drop gesture.

If you did not work with the D&D package, java.awt.dnd, two weeks ago, please take some time to browse through the classes and see what is there. Do not get me wrong; you should not memorize the methods, just look quickly through the classes of this package.

Hint: If you have not downloaded the Java API Documentation, now is the time to do so. See Getting started section for instructions.

Now you will try to make another small drag and drop test program. When you select a piece of text from your application and drag it to an external program that accepts drop gestures, like Word word WordPad, the text should appear in this application. For this you could use a GUI component of your choice, for example JTextField or JTextPane in your application.

This could be a bit more trick than it sounds if you have not worked with the DnD package before. Try to figure some of the connections between the classes yourself, but please search for some examples if you are completely stuck with this problem.

Hint: DragGestureListener , DragSourceListener , DragSource.createDefaultDragGestureRecognizer(...), DnDConstants.ACTION_COPY, java.awt.datatransfer.DataFlavor

Since we are aiming at a bookmark utility here, we also need to drop URLs to a browser. Confirm that this also works with your test application above, and make the necessary changes.



site: Håvard Rast Blok
mail:
updated: 27 July 2007