Question:

Java programming questions. Buttons opening other programs.

by  |  earlier

0 LIKES UnLike

What I am trying to do is make a one stop program that can open other programs and even hyperlinks for internet sites.

Is that possible?

I am looking on hints to help me do that but I'm coming up blank.

any thoughts on how to assign a button to a hyperlink or a button to open another program?

 Tags:

   Report

1 ANSWERS


  1. In your ActionListener, get the Runtime instance and use one of the forms of the exec() method.  This is not portable as you will need each installation to be configured so that you know the path & command string to call each desired program.  

    For example, to launch Notepad on Windows PCs, is easy:

    Runtime rt = Runtime.getRuntime();

    Runtime.exec("notepad");

    But for Firefox or Internet Explorer, you need to specify the path since they aren't normally in the System path:

    rt.exec(new String[]{"c:\Program Files\Mozilla Firefox\firefox.exe",

    "www.java.net"});

    rt.exec(new String[]{"c:\Program Files\Internet Explorer\iexplore.exe",

    "www.w3c.org"});

    Notice that you need the path to and name of the executable, as well as the fact that you need to either use "/" or "\" depending on operating system.  Probably best to do this where the user is asked to configure each button, using a JFileChooser to select the executable.  Then you can store the canonical path retrieved from the File object.  

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.