//JEditPane可以帮助你实现浏览器功能
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
public class JEditorPaneYay{
public static void main(String[] args){
JEditorPane editPane = null;
try{
URL address = new URL("http://blog.csdn.net/yinbodotcc");
editPane = new JEditorPane(address);
}catch(MalformedURLException e){
System.out.println("Malformed URL: " + e);
}catch(IOException e){
System.out.println("IOException: " + e);
}
editPane.setEditable(false);
final JEditorPane thePane=editPane;
//下面给他添加事件,这样当点击超级链接的时候,就能够达到更换页面的功能
editPane.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent hle){
try{
if (hle.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
thePane.setPage(hle.getURL());
}
catch(IOException ioe){
ioe.printStackTrace(System.err);
}
}
});
JFrame f = new JFrame("JEditorPane3");
f.setContentPane(new JScrollPane(editPane));
f.setSize(400,300);
f.show();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}