View Full Version : Need help with Java programming
SlashWylde
21st October 2006, 21:05
Hey folks,
I know there's a few of you out there who are familliar with programming in Java. I have an end of semester engineering project I'm working on and I'm trying to figure out how to open a file from the current directory when I click on a menu item in my GUI. I want open a PDF document when I click on the menu item as follows:
private void jMenuItemHelpFileActionPerformed(java.awt.event.Ac tionEvent evt) {
// Opens a PDF of the help file in Adobe Acrobat
}
I've scanned through the JAVA API's but I can't find anything which would be applicable.
Can someone please suggest a method to achive what I'm trying to do?
Much appreciated,
-SW
notme
21st October 2006, 21:38
private void jMenuItemHelpFileActionPerformed(java.awt.event.Ac tionEvent evt) {
start myfile.pdf
// Opens a PDF of the help file in Adobe Acrobat
}
Jamezo
21st October 2006, 21:44
You need to execute Adobe Reader or whatever with the location of the file as a run parameter (should be able to be tacked on to the end, eg. runCommand(".../reader.exe -..../dir1/helpfile.pdf", *any other parameters needed for the java execute command, I've never used it myself*)
Just what that execute command is I have no idea, but that's the basic idea that I think you will need to use.
Jamezo
21st October 2006, 22:09
I was thinking something like this:
Runtime rt = Runtime.getRuntime();
Process prcs = rt.exec(".../AcroRd32.exe -..../dir1/helpfile.pdf");
Where the exact filenames and paths are used instead. (I'm dead wrong on the runtime parameter syntax, I know that)
But even that seems to be not a very nice way of doing it. You should be able to open the file directly, like what Allun wrote.
xwhatsit
21st October 2006, 22:36
OK... I don't use Windows but I'm sure there are hooks within the Windows API or a particular executable file that will automatically launch a file within it's preferred program that you have set up. It's unwise to rely on absolute paths; different versions of Acrobat will be in different places, different versions of Windows etc etc.
What you should be looking for is something like `C:\Windows\Yadayadascree\openfile.exe mypdfdoc.pdf'.
Of course all this completely ruins one of the wonderful things about Java -- cross-platform compatibility. I would have thought there'd be some kind of 3rd-party class you can load in that will let you view PDFs within your program. PDF is an open standard after all. There are flaming millions of PDF viewers around.
My 2c.
Jamezo
21st October 2006, 23:18
Ah, top idea!
http://www.adobe.com/products/acrviewer/acrvdnld.html?name=Accept#java
Even Adobe makes a JavaBean you could use; plug it straight into your frame.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.