Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: cxtable/TextAreaConsole.java


1   package cxtable;
2   
3   /*this can be used to re-direct stdout/stderr to a Frame w/ a textarea..
4   Debugging..*/
5   
6   
7      import java.io.*;
8      import java.awt.*;
9      import java.awt.event.*;
10  
11      public class TextAreaConsole extends OutputStream{
12     
13        private TextArea ta;
14        private Panel p;
15     
16        public TextAreaConsole()
17        {
18        }
19     
20        public Panel create()
21        {
22           ta=new TextArea("",20,40);
23           p=new Panel();
24           p.add(ta);
25           return p;
26        }
27     
28       public Frame create_frame()
29       {
30       ta=new TextArea("",20,40);
31       Frame f = new Frame("Output from process...");
32       f.setLayout(new BorderLayout());
33       f.add(ta,BorderLayout.CENTER);
34       return f;
35       }
36  
37        public void println(String s)
38        {
39           ta.append(s);
40        }
41     
42        public void write(int i)
43        {
44           char c = (char)i;
45           print(""+c);
46        }
47        public void write(float f)
48        {
49           print(new Float(f));
50        }
51        public void write(long l)
52        {
53           print(new Long(l));
54        }
55        public void write(char[] c)
56        {
57           print(new String(""+c));
58        }
59        public void write(char c)
60        {
61           print(new Character(c));
62        }
63        public void write(String s)
64        {
65           print(s);
66        }
67     
68        public void write (double d)
69        {
70           print(new Double(d));
71        }
72     
73        public void print(Object s)
74        {  
75        ta.append(s.toString());
76        }
77     
78        public void clear()
79        {
80           ta.setText("");
81        }
82       
83     
84        public static void main(String[] args)
85        {
86           
87           TextAreaConsole tc= new TextAreaConsole();
88          OutputStream tac = (OutputStream)tc;
89    
90           final Frame  f=tc.create_frame();
91  
92           System.setOut(new PrintStream(tac));
93           System.setErr(new PrintStream(tac));
94        
95           f.addWindowListener(
96                                 new WindowAdapter()
97                                 {
98                                    public void windowClosing(WindowEvent we)
99                                    {f.setVisible(false);}
100                                });
101          f.pack();
102          f.setVisible(true);
103          System.out.println("HEHEHEHE");
104          System.out.print(".......");
105          System.out.println("...!");
106       }
107    
108    /*end*/
109    }
110 
111