Results 1 to 5 of 5
  1. #1
    bgdak is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default Output Message if Path is Non-Existent

    I have a button that when pressed starts an application. On some PC's the application does not exist. In those cases I would like to have a message pop up when the button is pressed stating that "The application is not installed". I would like to do this without changing the existing Runtime path. If the Runtime path does not exist I would like it to pop up the message above. I am new to this so thanks in advance for you patience.

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
    {
    try {
    Runtime.getRuntime().exec("\"C:/Program Files (x86)/AutoGraph/EasyCopy 8.1/easycopy.exe\"");
    } catch (java.io.IOException ex) {
    Logger.getLogger(CADMenu3.class.getName()).log(jav a.util.logging.Level.SEVERE, null, ex);
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default

    On some PC's the application does not exist. In those cases I would like to have a message pop up when the button is pressed

    The File class offers an exists() method that you can use to check that a file of some given name exists. (Java 7 lets you check whether you can execute the file). There is an example of its usage at Java Developers Almanac.

    Displaying a message in a dialog box is described in some detail in Oracle's Tutorial in the section How to Make Dialogs.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default

    Also a couple of points of style that are worth making habits as soon as possible. Method (and variable) names should be descriptive which jButton9ActionPerformed is not. Rather than accept NB's default names think of something descriptive. If the button bears the text "Copy", maybe copyHandler or something. (And, of course, the button itself would be copyBut not jButton9!)

    Secondly the argument is declared as "java.awt.event.ActionEvent" but it would be better to import that class and declare the argument as "ActionEvent". This, being briefer, is more easily readable. Additionally the import acts as a useful piece of program documentation describing the dependencies of this class. I have no idea if NB's behaviour in this regard can be corrected.

  4. #4
    bgdak is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    Thanks I will look into it.

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,569
    Rep Power
    12

    Default

    You're welcome - post back with what you are trying if you have problems.

Similar Threads

  1. Replies: 0
    Last Post: 09-30-2010, 09:16 PM
  2. Replies: 6
    Last Post: 06-04-2010, 09:43 PM
  3. setting class-path & Library Path in ubantu
    By programmer_007 in forum Eclipse
    Replies: 18
    Last Post: 02-22-2010, 01:31 PM
  4. output path
    By sardare in forum Eclipse
    Replies: 1
    Last Post: 03-16-2009, 05:14 AM
  5. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-26-2009, 12:44 AM

Posting Permissions

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