Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Catching Droped File On an application
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
copthesaint




PostPosted: Fri Nov 04, 2011 11:34 am   Post subject: Catching Droped File On an application

What I want to do is make a jar program that will startup when a file is dropped on the jar

for example textfile01.txt is moved and dropped on program.jar

I want 'program.jar' to then read the file.

Anyone know how I can do this?
I just want to read simple text.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Nov 04, 2011 1:06 pm   Post subject: RE:Catching Droped File On an application

well there's http://developer.apple.com/library/mac/documentation/Java/Reference/1.5.0/appledoc/api/com/apple/eawt/package-summary.html but the extensions have been deprecated so they might or might not work (or might stop working in the future).

I'm assuming you're developing for OSX. I don't know if other operating systems provide such events to applications.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DemonWasp




PostPosted: Fri Nov 04, 2011 1:59 pm   Post subject: RE:Catching Droped File On an application

For Windows, I recommend this StackOverflow question: http://stackoverflow.com/questions/382878/launching-java-classes-via-windows-drag-and-drop

The easiest way seems to be creating a file Windows sees as an executable (a .bat, though you could also use a .exe or more obscure executable format) that passes those arguments to your Java program. Then you drag your arguments to program.bat, which calls your Java stuff.

There's also a registry hack, but that looks a little insane for something so trivial.
Dan




PostPosted: Fri Nov 04, 2011 11:35 pm   Post subject: RE:Catching Droped File On an application

To add to what DemonWasp stated, on windows you can also acompish this with shortcuts if you make a shortcut to the java excutable and pass the arugments to run the jar. After that files droped on the shortcut should be passed as arugments.

However it would best to simply tell your users to pass the file as an arugment to the program as it would be the most portable soultion. If you want to make it more user friendly you could then make a GUI with a file browser which calls the application or look into APIs and event calls for when a file is droped on an active application's GUI (as Tony mentioned, tho almost all desktop enviroments support this in some way).
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
copthesaint




PostPosted: Wed Nov 09, 2011 9:18 am   Post subject: RE:Catching Droped File On an application

kk thanks both of you.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: