default browser from Java
In the event that one call from a Java application, a URL must have it on the sourceforge.net BrowserLauncher2 . With this library can be displayed with little code in an URL in the browser.
given to tie the file first BrowserLauncher2.jar in its classpath.
Then comes the import.
import edu.stanford.ejalbert.BrowserLauncher;
import edu.stanford.ejalbert.exception.UnsupportedOperatingSystemException import
;; edu.stanford.ejalbert.exception.BrowserLaunchingInitializingException
Finally, you write a method in which a browser launcher instance is created.
public static void launch browser () {
try {
/ / browser launcher instance create
browser launcher launcher = new browser launch ();
/ / calling a URL with the function openURLinBrowser
launcher.openURLinBrowser ( "http://broneo.blogspot.com");
} catch (BrowserLaunchingInitializingException ex) {System.out.println
(ex);
} catch (UnsupportedOperatingSystemException ex) {System.out.println
(ex);}
}
Now can be accessed via the browser launch function () the browser with the desired URL. Of course, one could make the whole even more dynamic by the browser function launch () the URL passed as parameter.
That would look like this.
public static void launch browser ( String url) {try {
/ / browser launcher instance create
browser launcher launcher = new browser launch ();
/ / calling a URL with the function openURLinBrowser
launcher.openURLinBrowser ( url );
} catch (BrowserLaunchingInitializingException ex) {
System.out.println (ex);
} catch (UnsupportedOperatingSystemException ex) {System.out.println
(ex);}
}
0 comments:
Post a Comment