1 import javax.swing.JEditorPane; 2 import javax.swing.event.HyperlinkListener; 3 import javax.swing.event.HyperlinkEvent; 4 import javax.swing.text.Document; 5 import java.net.URL; 6 7 class TextLogger 8 extends JEditorPane 9 { 10 public TextLogger () 11 throws java.io.IOException 12 { 13 // maDocument = getEditorKit().createDefaultDocument(); 14 super ("http://localhost"); 15 try 16 { 17 // setPage (new URL ("http://www.spiegel.de")); 18 } 19 catch (Exception e) 20 {} 21 22 setEditable (false); 23 final JEditorPane finalPane = this; 24 addHyperlinkListener (new HyperlinkListener() 25 { 26 public void hyperlinkUpdate (HyperlinkEvent e) 27 { 28 try 29 { 30 if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) 31 finalPane.setPage (e.getURL()); 32 } 33 catch (java.io.IOException ex) 34 { 35 ex.printStackTrace(System.err); 36 } 37 } 38 }); 39 } 40 41 public void appendText (String sText) 42 { 43 try 44 { 45 maDocument.insertString (maDocument.getLength(), sText, null); 46 } 47 catch (javax.swing.text.BadLocationException e) 48 {} 49 } 50 51 private Document maDocument; 52 } 53