Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Open Browser with Swing Button

461 views
Skip to first unread message

Rod

unread,
Jun 10, 2003, 5:25:09 AM6/10/03
to
newbie but need a solution quick

I need a button that will open my browser to a particular URL, say,
www.google.com.

Any help appreciated.


Daniel Dyer

unread,
Jun 10, 2003, 5:40:42 AM6/10/03
to

There's plenty of examples on the web of how to do this. If your code is
to run on multiple platforms you will need to use a different method for
each OS. Windows is fairly straightforward:

public void launchBrowser(URL target)
{
System.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " +
target.toString());
}

This launches whatever is the default browser (Opera, Mozilla, IE,
Netscape, whatever) for the particular URL. In fact it will launch
whatever the default viewer is for the file type (so you get Word, if it's
installed, for .doc files, etc.)

If you want to support Linux/Solaris/Mac you will need a more involved
solution (search the web).


--
Daniel Dyer
Empathy Software (http://www.empathysoftware.com)

Brock Heinz

unread,
Jun 10, 2003, 11:14:37 AM6/10/03
to
Daniel,

You mixed up 'System' with 'Runtime' The following code will work:

String url = "http://www.google.com";
try {
Runtime.getRuntime().exec(
"rundll32 url.dll,FileProtocolHandler " + url);
} catch (IOException e) {
e.printStackTrace();
}


-Brock


Daniel Dyer <dan....@dontspammeempathysoftware.com> wrote in message news:<oprqjo54epiihdmk@localhost>...

Jon A. Cruz

unread,
Jun 11, 2003, 12:27:06 AM6/11/03
to
0 new messages