Link to home
Start Free TrialLog in
Avatar of GloriousRain
GloriousRain

asked on

Launch Web Browser in an application?

Dear all,
How can i launch Web Browser in an Java application(not applet)?
ASKER CERTIFIED SOLUTION
Avatar of yongsing
yongsing

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
import java.util.*;
import java.io.*;
import java.text.*;

public class Test{

  public void runExplorer()throws Exception{
    Runtime temp=Runtime.getRuntime();

    temp.exec("c:\\progra~1\\Intern~1\\IExplore.exe");
  }
  public static void main(String[] args)throws Exception{
     Test a=new Test();
     a.runExplorer();
   
  }
}


Try this... hope this will help you.
May be you no need to import those packages..
You try to test the program by remove them one by one.
Ok. Good Luck
Avatar of GloriousRain
GloriousRain

ASKER

yongsing,
i couldn't open your link.
yongyih,
i don't want hardcode in my app. Is the address of IE always in the path you address? If not, how can i get the path in runtime?
yongyih,
one more thing: how about if i use Netscape?
This link works fine for me here. Why don't you try again?

To run Netscape:

Runtime.getRuntime().exec(
"C:\Program Files\Netscape\Communicator\Program\netscape.exe http://www.yahoo.com");

This will open Netscape with the URL to Yahoo!
The link will teach you how to launch the default browser on Windows platform.

http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
Dear all,
it's better if all you guys can give me the way to get the path for IE and Netscape because i don't want hardcode in my app.
GloriousRain, please refer to the URL I've given. I believe it teaches you how to launch the default browser in your system.
:) yongsing,
i still can't open. but i tell u the true, that i've found code in own our project shows how to launch Web in Java App, the code indicates it has origin from your link ( that reason y i give u points ). Now it's still not works fine because some difficult about multi OS problem. Thanks anyway!
Great to hear that you already found your answer ^^
Anyway, if don't want to hardcode it, just pass in the path as parameter..

Like this, you can run any exe file you want. ^^

public class Test{
 public void runProgram(String strPath)throws Exception{
   Runtime temp=Runtime.getRuntime();
   temp.exec(strPath);
 }
 public static void main(String[] args)throws Exception{
  Test a=new Test();
  a.runProgram("c:\\progra~1\\Intern~\\IExplore.exe");  
 }
}


yongyih,
"a.runProgram("c:\\progra~1\\Intern~\\IExplore.exe");"
->This is also hardcode man. I mean you can get the path from Registry or somewhere at runtime not code strings directly in your program at design time.