Results 1 to 6 of 6

Thread: Need help with Java programming

  1. #1
    Join Date
    31st January 2005 - 20:53
    Bike
    Vulcan - God of Fire
    Location
    Auckland
    Posts
    449

    Question Need help with Java programming

    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
    Destroy Everything! Destroy Everything! Destroy Everything! Obliterate what makes us weak!

  2. #2
    Join Date
    14th January 2005 - 21:26
    Bike
    ...
    Location
    NZ
    Posts
    856
    private void jMenuItemHelpFileActionPerformed(java.awt.event.Ac tionEvent evt) {

    start myfile.pdf

    // Opens a PDF of the help file in Adobe Acrobat

    }

  3. #3
    Join Date
    17th September 2004 - 21:20
    Bike
    Upgrading ^_^
    Location
    Boganville
    Posts
    335
    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.
    Eat the riches! Eat your money! The revolution will be DELICIOUS!!!

  4. #4
    Join Date
    17th September 2004 - 21:20
    Bike
    Upgrading ^_^
    Location
    Boganville
    Posts
    335
    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.
    Eat the riches! Eat your money! The revolution will be DELICIOUS!!!

  5. #5
    Join Date
    24th September 2006 - 02:00
    Bike
    -
    Location
    -
    Posts
    4,736
    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.

  6. #6
    Join Date
    17th September 2004 - 21:20
    Bike
    Upgrading ^_^
    Location
    Boganville
    Posts
    335
    Ah, top idea!

    http://www.adobe.com/products/acrvie...me=Accept#java

    Even Adobe makes a JavaBean you could use; plug it straight into your frame.
    Eat the riches! Eat your money! The revolution will be DELICIOUS!!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •