| |
14. 36. 2. 从JEditorPane组件监听超链接事件 |
|
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class Main {
public static void main(String[] argv) throws Exception{
String url = "http://java.sun.com";
JEditorPane editorPane = new JEditorPane(url);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(new MyHyperlinkListener());
}
}
class MyHyperlinkListener implements HyperlinkListener {
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
JEditorPane pane = (JEditorPane) evt.getSource();
try {
// Show the new page in the editor pane.
pane.setPage(evt.getURL());
} catch (IOException e) {
}
}
}
}
|
|
14. 36. Web浏览器 | | 14. 36. 1. | 浏览器JEditorPane | |  | | 14. 36. 2. | 从JEditorPane组件监听超链接事件 | | |
|