//try this code below, it will help
//it is a simple IE explorerimport java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;public class Test2 extends JFrame {
private JTextField enterField;
private JEditorPane contentsArea;
private String add = new String("http://www.yahoo.com"); public Test2()
{
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[] )
{
Test2 application = new Test2(); application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );
}}
//it is a simple IE explorerimport java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;public class Test2 extends JFrame {
private JTextField enterField;
private JEditorPane contentsArea;
private String add = new String("http://www.yahoo.com"); public Test2()
{
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[] )
{
Test2 application = new Test2(); application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货