getAppletContext().showDocument(url3,'_top');showDocument
public void showDocument(URL url,
                         String target)
Requests that the browser or applet viewer show the Web page indicated by the url argument. The target argument indicates in which HTML frame the document is to be displayed. The target argument is interpreted as follows: "_self"  Show in the window and frame that contain the applet. 
"_parent" Show in the applet's parent frame. If the applet's frame has no parent frame, acts the same as "_self". 
"_top"  Show in the top-level frame of the applet's window. If the applet's frame is the top-level frame, acts the same as "_self". 
"_blank"  Show in a new, unnamed top-level window. 
name Show in the frame or window named name. If a target named name does not already exist, a new top-level window with the specified name is created, and the document is shown there. An applet viewer or browser is free to ignore showDocument.Parameters:
url - an absolute URL giving the location of the document.
target - a String indicating where to display the page.--------------------------------------------------------------------------------showStatus
public void showStatus(String status)
Requests that the argument string be displayed in the "status window". Many browsers and applet viewers provide such a window, where the application can inform users of its current state.
Parameters:
status - a string to display in the status window.

解决方案 »

  1.   

    Goto to a new URL from an Applet
    You have to use getAppletContext().showDocument
         (new URL("http://www.whatever.com"));
     
    or
    getAppletContext().showDocument
         (new URL("http://www.whatever.com"),"HTML frame ID");
     
    NOTE: If "HTML frame ID" do not exists then a new browser window will be opened.For example, we want to display lowres.html page if resolution is 640x480 else the hires.html is used.
    import java.applet.*;    
    import java.awt.*;
    import java.net.*;public class whatres extends Applet {
      public void init() {
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        if (dim.width==640 && dim.height==480) {
           try {
             getAppletContext().showDocument
               (new URL(getCodeBase()+"lowres.html"),"_top");
             }
           catch (Exception ex) {}
          }
        else {
           try {
             getAppletContext().showDocument
               (new URL(getCodeBase()+"hires.html"),"_top");
             }
           catch (Exception ex) {}
          }
      }
    }
     NOTE: The previous example works only so long as the document was retrieved without specifying an actual document name, since getDocumentBase() returns the full URL including the name of the document. If the document name was specified, you should try something like this or specify the complete URL (thanks to Rob Judd): :  try {
        String docString = getDocumentBase().toString();
        if (docString.endsWith("/")) {
          getAppletContext().showDocument
            (new URL(getDocumentBase()+"lowres.html"), "_top");
            } 
        else {
          getAppletContext().showDocument
            (new URL(getDocumentBase()+"/../lowres.html"), "_top");
            }
        } 
        catch (Exception e) {} 
    Another example, type a new URL in a textfield, and press a button to go to that page.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;public class GotoURLButton extends Applet implements
        ActionListener {
      Button b;
      TextField t;
      
      public void init() {
         t = new TextField(20);
         add(t);
         b = new Button("Go to this URL");
         add(b);
         b.addActionListener(this);
         }
      
      public void actionPerformed(ActionEvent ae) {
         if (ae.getSource() == b) {
           try {
             getAppletContext().showDocument(new URL(t.getText()));
             }
           catch (Exception e) {
             e.printStackTrace();
             }
           }
         }
      } 
      

  2.   

    源码如下:import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.net.*;
    public class Urltest extends Applet implements ItemListener{

    Choice choice1;
    TextField text1,text2;
    URL url1,url2,url3,url4,url5,url6;
    String s1,s2,s3,s4,s5,s6;

    public void init() 
    {
    setLayout(new GridLayout(2,2));
    choice1 = new Choice();
    text1 = new TextField(10);
    text2 = new TextField(10);
    choice1.add("清华大学");
    choice1.add("大连理工");
    choice1.add("yahoo");
    choice1.add("263");
    add(choice1);
    add(new Label("选择一个网址"));
    add(text1);
    add(text2);
    choice1.addItemListener(this);
    s1 = "http://www.tsinghua.edu.cn";
    s2 = "http://www.dlut.edu.cn";
    s3 = "http://www.yahoo.com";
    s4 = "http://www.263.net";
    }

    public void itemStateChanged(ItemEvent e)
    {
    if(choice1.getSelectedIndex() == 0)
    {
    try
    {
    url1 = new URL(s1);
    }
    catch(MalformedURLException g)
    {
    System.out.print("不正确的URL:" + url1);
    }
    text1.setText("清华大学");
    getAppletContext().showDocument(url1);
    }
    if(choice1.getSelectedIndex() == 2)
    {
    try
    {
    url3 = new URL(s3);
    }
    catch(MalformedURLException g)
    {
    System.out.print("不正确的URL:" + url3);
    }
    text1.setText("yahoo");
    getAppletContext().showDocument(url3,"_blank");
    // getAppletContext().
    }
    else{};

    }}