open Web Page - Java Native OS

Java examples for Native OS:Browser

Description

open Web Page

Demo Code


import java.awt.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class Main{
    public static void openWebPage(URI uri) {
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop
                .getDesktop() : null;//from  ww w. j  a va  2s . c o  m
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(uri);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    public static void openWebPage(URL url) {
        try {
            openWebPage(url.toURI());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }
    public static void openWebPage(String urlString) {
        try {
            openWebPage(new URL(urlString));
        } catch (MalformedURLException e) {
            Errors.exceptionDialog("URL Exception",
                    "A malformed url exception occured", e.getMessage(), e);
        }
    }
}

Related Tutorials