import java.awt.BorderLayout;
import java.awt.Container;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
public class Test1 extends JFrame implements HyperlinkListener {
public Test1(){
Container c = getContentPane();
setSize(539,412);
setTitle("QQ登录界面");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JEditorPane pane = new JEditorPane();
pane.setContentType("text/html");
pane.setEditable(false);
pane.addHyperlinkListener(this);
File file = new File("http://E://Eclipse//workspace//QQ//src//qq//QQ.html");
String path = file.getAbsolutePath();
try {
pane.setPage(path);
} catch (IOException e) {
// TODO 自动生成的 catch 块
//System.out.println("读取页面 " + path + " 出错. " + );
e.printStackTrace();
}
pane.setBounds(0, 0, 539, 199);
c.add(pane);
setVisible(true);
}
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
// TODO 自动生成的方法存根
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
JEditorPane pane = (JEditorPane) e.getSource();
if (e instanceof HTMLFrameHyperlinkEvent)
{
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
HTMLDocument doc = (HTMLDocument) pane.getDocument();
doc.processHTMLFrameHyperlinkEvent(evt);
}
else
{
try
{
pane.setPage(e.getURL());
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
new Test1();
}
}
图片是运行结果和异常