Friday, September 14, 2012

Use Default Browser to Open a Web Page from a Swing Application

Prerequisite: Java 6+

public class DesktopBrowser {

   public static void main(String[] args) {
      try {
         String url = "http://www.google.com";
         java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
         }
      catch (java.io.IOException e) {
         System.out.println(e.getMessage());
         }
      }

   }
}