心情 天空

 




 










访




R
S
S

我的 Blog:
jybbh 最新的 20 条日志
[Ken的日志]
[工作心得]
[编程相关]
[潮汕文化]
[计算机相关]
[WEB相关]
[JAVA相关]
[Eclipse相关]
[Tomcat相关]
[SQL]
全站 Blog:
全站最新的 20 条日志
继承JEditorPane实现超连接监听事件HyperlinkListener [2005-11-18]
jybbh 发表在 JAVA相关

继承JEditorPane实现超连接监听事件HyperlinkListener

class HTMLPane extends JEditorPane implements HyperlinkListener
{
final JEditorPane paneRefefernce;
public HTMLPane(String content) throws IOException {
    paneRefefernce = this;
super(content);
    addHyperlinkListener(this);
    paneRefefernce = this;
setEditable(false);
}
    public void hyperlinkUpdate(HyperlinkEvent e) {
        try {
            if ( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED
            )
            paneRefefernce.setPage(e.getURL());
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
        }
    }
}
调用:
StringBuffer sb = new StringBuffer();
DataInputStream istr =
new DataInputStream(
new BufferedInputStream(
new FileInputStream("1.txt")));
BufferedReader reader = new BufferedReader(new InputStreamReader(istr));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
display.setText(sb.toString());
display.setContentType("text/html");

-------------------------------------
引用:http://dev.hackbase.com/hackbase10/how300094.htm
≡≡≡≡≡ 评论(共 条)我要评论
 

Copyright 2004 酷酷小家园   Powered by 5dblog