Results 1 to 5 of 5
- 01-28-2011, 06:14 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
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);
}
- 01-28-2011, 08:31 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 01-28-2011, 08:40 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
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.
- 01-28-2011, 09:14 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Thanks I will look into it.
- 01-28-2011, 09:17 PM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Similar Threads
-
how to get the resultset output into an output file
By renu in forum New To JavaReplies: 0Last Post: 09-30-2010, 08:16 PM -
java message box, how to not show multiple message box with same title or content
By oohay in forum AWT / SwingReplies: 6Last Post: 06-04-2010, 08:43 PM -
setting class-path & Library Path in ubantu
By programmer_007 in forum EclipseReplies: 18Last Post: 02-22-2010, 12:31 PM -
output path
By sardare in forum EclipseReplies: 1Last Post: 03-16-2009, 04:14 AM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-25-2009, 11:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks