2014. 12. 23. 22:36
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package practice;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import javax.swing.JOptionPane;

public class MainClass {
   
    private static final String errMsg="Error attempting to launch web browser";
   
  public static void main(String[] argv) throws Exception {
     
      String osName = System.getProperty("os.name");
      System.out.println(osName);
      String url="www.google.com";
      try {
                  if (osName.startsWith("Mac Os")){
                      Class<?> fileMgr =Class.forName("com.apple.eio.FileManager");
                      Method openURL= fileMgr.getDeclaredMethod("openURL", new Class[] {String.class});
                      openURL.invoke(null, new Object[] {url});
                  }else if(osName.startsWith("Windows")){
                      Runtime.getRuntime().exec("rundll32 url.dll, FileProrocolHandler " + url);
                  }else{
                      String[] browsers={"firefox", "opera", "konqueror","epiphany","mozilla","netscape"};
                      String browser=null;
                      for(int count=0; count < browsers.length && browser==null;count++){
                          if(Runtime.getRuntime().exec(new String[]{"which", browsers[count]}).waitFor()==0 ){
                              browser=browsers[count];
                              }
                          }
                      if(browser==null){
                          throw new Exception("Could not find and web browser");
                      }else{
                          Runtime.getRuntime().exec(new String[]{browser, url});
                          }
                     
                      }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage());
       
    }
     
     
  }
}

'Java' 카테고리의 다른 글

DataInputStream / DataOutputStream  (0) 2014.12.25
Finding IP using the domain name  (0) 2014.12.25
Multi Chatting  (0) 2014.12.25
class StringBuilder  (0) 2014.12.24
Runtime.getRuntime().exec()  (0) 2014.12.24
Posted by af334