applet.getAppletContext().showDocument(URL url, String target)

解决方案 »

  1.   

    //try this, this is an application, if u like 
    //you can just simply change it to applet
    //good luckimport java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;public class Test extends JFrame {
       private JTextField enterField;
       private JEditorPane contentsArea;
       private String add = new String("http://www.yahoo.com");   public Test()
       {
          super( "Simple Web Browser" );      Container container = getContentPane();      enterField = new JTextField( add );      enterField.addActionListener(         new ActionListener() {            public void actionPerformed( ActionEvent event )
                {
                   getThePage( event.getActionCommand() );
                }
             }
          );      container.add( enterField, BorderLayout.NORTH );
          contentsArea = new JEditorPane();
          contentsArea.setEditable( false );      contentsArea.addHyperlinkListener(         new HyperlinkListener() {            public void hyperlinkUpdate( HyperlinkEvent event )
                {
                   if ( event.getEventType() ==
                        HyperlinkEvent.EventType.ACTIVATED )
                      getThePage( event.getURL().toString() );
                }
             }      );      container.add( new JScrollPane( contentsArea ),
             BorderLayout.CENTER );      setSize( 400, 300 );
          setVisible( true );      this.getThePage(add) ;
       }   private void getThePage( String location )
       {
          setCursor( Cursor.getPredefinedCursor(
             Cursor.WAIT_CURSOR ) );      try {
             contentsArea.setPage( location );
             enterField.setText( location );
          }      catch ( IOException ioException ) {
             JOptionPane.showMessageDialog( this,
                "Error retrieving specified URL",
                "Bad URL", JOptionPane.ERROR_MESSAGE );
          }      setCursor( Cursor.getPredefinedCursor(
             Cursor.DEFAULT_CURSOR ) );
       }   public static void main( String args[] )
       {
          Test application = new Test();      application.setDefaultCloseOperation(
             JFrame.EXIT_ON_CLOSE );
       }}