open IMDB Webpage - Java Native OS

Java examples for Native OS:Browser

Description

open IMDB Webpage

Demo Code


//package com.java2s;
import java.awt.Desktop;
import java.net.URI;
import java.net.URL;

public class Main {
    public static void main(String[] argv) throws Exception {
        String id = "java2s.com";
        openIMDBWebpage(id);// www .  java 2  s  .c om
    }

    public static void openIMDBWebpage(String id) {
        openWebpage("http://www.imdb.com/title/" + id + "/");
    }

    public static void openWebpage(String link) {
        try {
            URL url = new URL(link);
            openWebpage(url.toURI());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void openWebpage(URI uri) {
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop
                .getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(uri);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

Related Tutorials