Open Browser when JButton clicked

Is it possible to open up a IE or firefox etc. browsers which will list all the files in the specified URL when a JButton is clicked.

[140 byte] By [Mickey123a] at [2007-11-27 11:26:59]
# 1

absolutely

You can either use the Runtime class to run IE externally, or you can use the JDIC WebBrowser component to embed it in your app

tjacobs01a at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 2

can you give me a sample code or a webpage containing the information. i tried but unable to find it

Thanks

Mickey123a at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 3

Runtime example: Put this code in your actionPerformed (or what ever you are using). This will not be platform independent since there are people who doesn't have IExplorer and also there are people having IExplorer in another directory than in this example. so this is not very good.

try{

// Execute a command

//OBS: you have to get the command right , you have to know were the browser is located

String command = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";

Process child = Runtime.getRuntime().exec(command);

}

catch(Exception exc){

System.out.println("Problem executing command. " +exc);

}

Other solotions

Have a look at this link: http://www.croftsoft.com/library/tutorials/browser/

(It is telling you that this problem is solved very easy with an Applet and that if you have not an Applet you can use the Non-Core API JNLP)

Ja_Lava_Javaa at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 4

> Runtime example: Put this code in your actionPerformed (or what ever you are using). This will not be platform independent since there are people who doesn't have IExplorer and also there are people having IExplorer in another directory than in this example. so this is not very good.

As I always, say, for people looking for such features, it is always best in this case to switch to JDK 6.0 for a much simpler and more cross platform approach than using the the runtime exec method.

In JDK 6.0 you, have the java.awt.Desktop class which can be used to launch the default system browser when given a URL. Hence you do not have to know the location of the browser exe to launch it.

try {

URI url = new URI("http://www.google.com");

Desktop.getDesktop().browse(url);

} catch(Exception e) {

e.printStackTrace();

}

ICE

icewalker2ga at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 5

Isnt there any Funda of accessing defaut Browser,.

I mean i want to keep my application OS independent.

Please give me a better option.

Neo_Javaa at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 6

Thanks. Also how do i access a directory from a remote server. .i want this directory show up as a list in the default web browser. ftp is not supported.

Mickey123a at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 7

never mind. got the solution

Mickey123a at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 8

icewalker2g :

> As I always, say, for people looking for such

> features, it is always best in this case to switch to

> JDK 6.0 for a much simpler and more cross platform

> approach than using the the runtime exec method.

Ah, sorry - I need to update my knowledge. I say thanks too.

Ja_Lava_Javaa at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...
# 9

> Ah, sorry - I need to update my knowledge. I say thanks too.

Always glad to be of assistance

ICE

icewalker2ga at 2007-7-29 16:13:40 > top of Java-index,Desktop,Core GUI APIs...