/Users/lyon/j4p/src/gui/html/TextViewer.java

1    package gui.html; 
2     
3    import gui.ClosableJFrame; 
4     
5    import javax.swing.*; 
6     
7     
8    public class TextViewer extends ClosableJFrame { 
9     
10       private JEditorPane textPane 
11               = new JEditorPane(); 
12    
13       public TextViewer() { 
14           super("TextViewer"); 
15           java.awt.Container c = getContentPane(); 
16           c.setLayout(new java.awt.GridLayout(1, 0)); 
17           c.add(new JScrollPane(textPane)); 
18           setSize(400, 400); 
19           setVisible(true); 
20       } 
21    
22    
23       public void setRtfText(String s) { 
24           textPane.setContentType("text/rtf"); 
25           textPane.setText(s); 
26       } 
27    
28       public void setPlainText(String s) { 
29           textPane.setContentType("text/plain"); 
30           textPane.setText(s); 
31       } 
32    
33       public void setString(String s) { 
34           setPlainText(s); 
35           System.out.println(s); 
36       } 
37       public void println(Object o){ 
38           if (o == null ) return; 
39           String s = textPane.getText(); 
40           s = s +"\n"+ o.toString(); 
41           textPane.setText(s); 
42       } 
43    
44       public static void main(String args[]) { 
45           TextViewer tv = new TextViewer(); 
46           tv.println("Hello World"); 
47           for (int i=0; i < 100; i++) 
48               tv.println("i="+i); 
49       } 
50   }