Thursday, November 8, 2012

How to open a link on your Web Browser via Java Application.

Alright. Now I'm gonna make a quick update on how do you open a URL on your Default Web Browser via your Java Application. Here's the code.

if (!java.awt.Desktop.isDesktopSupported()) {
            JOptionPane.showMessageDialog(null, "Desktop is not supported.", "Desktop Not Supported!", JOptionPane.ERROR_MESSAGE);
        }
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();


 if (!desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
            JOptionPane.showMessageDialog(null, "Desktop is not supported for browsing.", "Desktop Not Supported For Browsing!", JOptionPane.ERROR_MESSAGE);
        }

        try {
            java.net.URI uri = new java.net.URI("http://10poet.blogspot.com");
            desktop.browse(uri);
        } catch (Exception e) {
            e.printStackTrace();
        }


Yes. It's that simple. So try it out. And tell me how it went. See you soon again! :)




No comments:

Post a Comment