DropEvent
- description
- a drop event will be returned to processing whenever you drop a file or a folder onto your running sketch or application.
- +Example
/** * basic example of a drop event and its contained informations. * drag an image, a file, a folder, a link into the sketch and see * what information the console spits out. * code by andreas schlegel. http://www.sojamo.de/libraries/drop */ import sojamo.drop.*; SDrop drop; void setup() { size(400,400); frameRate(30); drop = new SDrop(this); } void draw() { background(0); } void dropEvent(DropEvent theDropEvent) { // returns a string e.g. if you drag text from a texteditor // into the sketch this can be handy. println("toString()\t"+theDropEvent.toString()); // returns true if the dropped object is an image from // the harddisk or the browser. println("isImage()\t"+theDropEvent.isImage()); // returns true if the dropped object is a file or folder. println("isFile()\t"+theDropEvent.isFile()); // if the dropped object is a file or a folder you // can access it with file() . for more information see // http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html println("file()\t"+theDropEvent.file()); // returns true if the dropped object is a bookmark, a link, or a url. println("isURL()\t"+theDropEvent.isURL()); // returns the url as string. println("url()\t"+theDropEvent.url()); // returns the DropTargetDropEvent, for further information see // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/dnd/DropTargetDropEvent.html println("dropTargetDropEvent()\t"+theDropEvent.dropTargetDropEvent()); }
- Methods
- component ( )
- get the component of the drop event.
- dropTargetDropEvent ( )
- get the DropTargetDropEvent of the drop event. take a look at the documentation at api/java/awt/dnd/DropTargetDropEvent
- file ( )
- when dropping a file or a folder onto the applet you get a java File back. for accessing the content of this file please see the java documentation at api/java/io/File before making a call to the file() method, make sure the File is not null. you can check this with the theDropEvent.isFile() method, which will return true or false.
- filePath ( )
- filePath returns the absolute path of a file.
- isFile ( )
- check if the drop event was of type java.io.File.
- isImage ( )
- check if drop event is an image of type java.awt.Image
- isURL ( )
- check if drop event is an url, e.g. and url drag/dropped from a browser.
- listFiles ( )
- list files in a folder, recursive is optional, use true or false. to list with a limited depth use an int between 0 and n. taken from http://snippets.dzone.com/posts/show/1875
- listFilesAsArray ( )
- list files in a folder, recursive is optional, use true or false. to list with a limited depth use an int between 0 and n. taken from http://snippets.dzone.com/posts/show/1875
- loadImage ( )
- load an image from an URL or from a harddisk. before calling loadImage(), check with isImage() if there is an image available.
- text ( )
- when dropping text onto the applet you can access the text with the getText() method.
- url ( )
- if an URL was dropped onto the applet the url() method returns the same as String.
- x ( )
- get the x coordinate where the object was dropped.
- y ( )
- get the y coordinate where the object was dropped.
- usage
- Web & Application
- related