HI Dave,
To launch an application you can use Runtime class.
Following is the code;
public void launchBrowser(String url) throws Exception
{
Runtime rt = Runtime.getRuntime();
try {
// for IE to launch;
Process proc = rt.exec("iexplore " + url);
}catch(Exception ex) {
// for netscape
Process proc = rt.exec("netscape " + url);
}
rt = null;
Bye,
S.M.Reddy.
Thanks for all the replies!
S.M.Reddy. I tried your code, everything compiled fine, but as I try to execute it nothing happened. Am I missing something?here's the code:
try
{
launchBrowser("http://www.jmu.edu");
}
catch (Exception e){}
public void launchBrowser(String url) throws Exception
{
Runtime rt = Runtime.getRuntime();
try {
// for IE to launch;
Process proc = rt.exec("iexplore " + url);
}catch(Exception ex) {
// for netscape
//Process proc = rt.exec("netscape " + url);
}
rt = null;
}
thanks again,
Dave
For one, you are missing exception handling code, so that no one has any clue what the problem might be.
Here's a probable cause: your system cannot find iexplore.exe or netscape.exe because their directories are not listed in the PATH environment variable. You'll need to either make sure that they are or use full paths - "c:/program files/netscape/netscape.exe" for example.
Or go the other way and let the system deside which browser to use: try to exec "start http://www.google.com" and "rundll32 url.dll,FileProtocolHandler http://www.google.com". This will work on windoze only, though...
Thanks again!
I was able to get the code from javaworld to work. One more question if you're still around. What swing text component would handle html tag or a link.Say I want to display a lot of text ( i use jtextarea), and there's a URL in the text, how would I be able to just click the URL and go to the website (what text component would handle links)?
thanks,
Dave