|
我 的 日 历 |
|
最 新 评 论 |
|
友 情 链 接 |
|
搜 索 日 志 |
|
访 问 计 数 |
|
获 取 R S S |
|
|
继承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 | | |
|