当前位置: 技术问答>java相关
请问:在JAVA中有象IE浏览器的容器类吗?
来源: 互联网 发布时间:2017-03-31
本文导语: 请问:在JAVA中有象IE浏览器的容器类吗? 它可以实现动态的页面更新吗?有可以告诉我是那一个类吗?//// | //try this code below, it will help //it is a simple IE explorer import java.awt.*; import java...
请问:在JAVA中有象IE浏览器的容器类吗?
它可以实现动态的页面更新吗?有可以告诉我是那一个类吗?////
它可以实现动态的页面更新吗?有可以告诉我是那一个类吗?////
|
//try this code below, it will help
//it is a simple IE explorer
import 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 explorer
import 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 );
}
}
|
javax.swing.JEditorPane
|
上面的代码不能显示中文网页,因为中文网页使用的gb2312标准.打开中文网页时会产生一个java.lang.NullPointerException异常.我最近在写一个解析html文档的解析器,也遇到了上面的问题.请问要怎样解决这个问题?