try {
        Runtime.getRuntime().exec("explorer http://www.sohu.com");
      } catch (IOException e1) {}

解决方案 »

  1.   

    我在以下事件中加入后还是出错。。
    void jButton1_actionPerformed(ActionEvent e) 
    {
     try {
            Runtime.getRuntime().exec("explorer http://cn.yahoo.com");
          } 
          catch (IOException e1) {}
    }
      

  2.   

    ·如果使用“Runtime的exec方法”调用浏览器程序的话,最好加上浏览器的判断:
    String vendor = System.getProperty("java.vendor");
    if(vendor.equals("Netscape Communications Corporation")){
    //使用Netscape...
    } else if(vendor.equals("Sun MicroSystem Inc.")) {
    //使用AppletViewer...
    } else {
    //使用IE...
    }·使用AppletContext。如下:
    try {
    getAppletContext().showDocument(new URL("http://www.abc.com"), "_blank");
    } catch (MalformedURLException e) {
    //error handle
    }建议使用第二种方法。
      

  3.   

    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import java.net.*;
    import java.applet.AppletContext;
    import javax.swing.*;public class MyApp extends JApplet
    {
    public void init(){
       JButton b = new JButton("www.yeah.net");
       b.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
              try{
                 URL url = new URL("http://www.javasoft.com/index.html");
                 System.out.println("http://www.javasoft.com/index.html");
                 getAppletContext().showDocument(url);
              }
              catch(MalformedURLException murl){
                 System.out.println("bad url !");
              }   
           } 
        
       }); 
          JButton b1 = new JButton("1");
          b1.setFocusPainted(true);
          
          JButton b2 = new JButton("2");
        //  b2.setDefaultCapable(true); 
        //  JRootPane jrp = this.createRootPane();  
              
        //  jrp.setDefaultButton(b2);
       //   setRootPane(jrp);
              
          getContentPane().setLayout(new FlowLayout());    
       getContentPane().add(b);
       getContentPane().add(b1);
       getContentPane().add(b2);
       b1.setSelected(true);
    }

    }
      

  4.   

    谢谢两位!
    hexiaofeng(java爱好者)、(怪侠一枝梅) 先谢谢了成功后一定给分。
      

  5.   

    还是不成功。。
    有没有例子呀。JB中
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    //import java.io.IOException ;
    import java.net.*;
    import java.applet.AppletContext;
    import javax.swing.*;public class Applet3 extends Applet {
      boolean isStandalone = false;
      JButton b = new JButton();
      JButton b1 = new JButton();
      JButton b2 = new JButton();
      //Get a parameter value
      public String getParameter(String key, String def) {
        return isStandalone ? System.getProperty(key, def) :
          (getParameter(key) != null ? getParameter(key) : def);
      }  //Construct the applet
      public Applet3() {
      }
      //Initialize the applet
      public void init() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception {
        b.setBounds(new Rectangle(94, 115, 73, 29));
        b.setText("江阴");
        b.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            b_actionPerformed(e);
          }
        });
        this.setLayout(null);
        b1.setText("常州");
        b1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {      }
        });
        b1.setBounds(new Rectangle(370, 112, 73, 29));
        b2.setText("无锡");
        b2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {      }
        });
        b2.setBounds(new Rectangle(618, 115, 73, 29));
        this.setBackground(Color.lightGray);
        this.add(b, null);
        this.add(b1, null);
        this.add(b2, null);
      }
      //Get Applet information
      public String getAppletInfo() {
        return "Applet Information";
      }
      //Get parameter info
      public String[][] getParameterInfo() {
        return null;
      }  void b_actionPerformed(ActionEvent e) {
    try {
        getAppletContext().showDocument(new URL("http://cn.yahoo.com"), "_blank");
        }
      catch  (MalformedURLException   e)
       {      //error handle
        }
      }
    }
      

  6.   

    void b_actionPerformed(ActionEvent e) {
    try {
        getAppletContext().showDocument(new URL("http://cn.yahoo.com"), "_blank");
        }
      catch  (MalformedURLException   e)
       {      //error handle
        }
      }有错!
      

  7.   

    swingcoder(swingcoder)错什么地方?
      

  8.   

    原因:
    在void b_actionPerformed(ActionEvent e)定义了变量e,在catch MalformedURLException e)又定义了变量e,造成重复定义。办法:
    修改catch MalformedURLException e)为catch MalformedURLException ex)