当前位置: 技术问答>java相关
请问在applet中怎么打开html(asp,jsp)页!
来源: 互联网 发布时间:2017-03-30
本文导语: 请问在applet中怎么打开html(asp,jsp)页! | applet.getAppletContext().showDocument(URL url, String target) | //try this, this is an application, if u like //you can just simply change it to applet //go...
请问在applet中怎么打开html(asp,jsp)页!
|
applet.getAppletContext().showDocument(URL url, String target)
|
//try this, this is an application, if u like
//you can just simply change it to applet
//good luck
import 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 );
}
}
//you can just simply change it to applet
//good luck
import 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 );
}
}