Redirecting System.out to a textfield

I want the output created by System.out (especially error messages) redirected to a textfield in stead of the console. How can I do this?
[144 byte] By [weelink] at [2007-9-27 20:59:38]
# 1

this is how I've done it. Just create a new instance of this class and pass in your TextArea. It redirects System.out and checks for messages on System.out every 5 seconds.

import java.io.*;

import javax.swing.*;

public class TextOut

implements Runnable

{

private JTextArea text;

private Reader in;

private Thread t;

public TextOut( JTextArea text )

throws Exception

{

this.text = text;

PipedOutputStream pout = new PipedOutputStream();

System.setOut( new PrintStream( pout ) );

in = new InputStreamReader( new PipedInputStream( pout ) );

t = new Thread( this );

t.start();

}

public void run()

{

while( true )

{

try

{

StringBuffer buffer = null;

while( in.ready() )

{

if ( buffer == null ) buffer = new StringBuffer();

buffer.append( (char)in.read() );

}

if ( buffer != null )

{

text.append( buffer.toString() );

java.awt.Rectangle r = new java.awt.Rectangle();

text.computeVisibleRect( r );

text.repaint( r );

}

t.sleep( 5000 );

} catch (IOException ioe) {

text.append( "" + ioe );

} catch (InterruptedException ie ) {

text.append( "" + ie );

}

}

}

}

mcalm01 at 2007-7-7 2:40:04 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...