Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Textfield output redirecting

Reply
Thread Tools

Textfield output redirecting

 
 
Olivier Merigon
Guest
Posts: n/a
 
      05-03-2004
Hi,

I'am looking for a set of class that can be used to redirect standard
output and standard input to a Text field like composant.
Example:
When I do a System.out.println("test"), I want the text to be displyed in a
text field composant instead of bieng displayed in the console.

I am sure a lot of people have already done that? so I was wondering if
somebody can give me a link to find ready to use classes that do the job.

Thanks in advance,


Olivier


 
Reply With Quote
 
 
 
 
mromarkhan@rogers.com
Guest
Posts: n/a
 
      05-18-2004

Peace be unto you
Here is a guess.
Disclaimer: Resources may not be released properly.
<code>
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Redirect_v2 extends JFrame
{
JTextArea jtextarea;
ByteArrayOutputStream byteStream;
ReadSystemOut readThread;
public Redirect_v2() throws IOException
{
byteStream= new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteStream);
System.setOut(printStream);
jtextarea = new JTextArea();
jtextarea.setText(byteStream.toString());
this.getContentPane().add(new JScrollPane(jtextarea),BorderLayout.CENTER);
this.setSize(512,342); //hypercard
this.setVisible(true);
readThread = new ReadSystemOut();
readThread.start();
this.addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
readThread =null;
System.exit(0);
}
}
);
//References:Message-ID: <c752mo$f52$(E-Mail Removed)>
//Example:When I do a System.out.println("test"), I want the text to be displyed in a
//text field composant instead of bieng displayed in the console
System.out.println("Peace be unto you");
System.out.println("http://www.hti.umich.edu/cgi/k/koran/koran-idx?type=simple&q1=peace&size=First+100");
}


public static void main(String [] s) throws IOException
{
new Redirect_v2();
}

public class ReadSystemOut extends Thread
{
Runnable doGet = new Runnable()
{
public void run()
{
String text = byteStream.toString();
if(byteStream.size() > 0)
{
jtextarea.append(text);
byteStream.reset();
}
}
};
public void run()
{
Thread myThread = Thread.currentThread();
while (readThread == myThread)
{
SwingUtilities.invokeLater(doGet);
try
{
this.sleep(1000l);
}
catch(InterruptedException ie)
{
}
}
}
}
}
</code>

Haca -- Have a good day.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting unittest output to a Text widget MrBlueSky Python 2 05-10-2006 08:22 AM
Redirecting print output to different queues / printers Paul Aspinall ASP .Net 0 02-26-2006 12:02 PM
RE: Redirecting system output quietly Eddie Parker Python 4 11-16-2004 06:01 PM
Output VALUE of INPUT textfield using document.write Stumped and Confused Javascript 13 09-23-2004 02:50 AM
stdout funniness from os.system() calls when redirecting output Birch Python 3 10-21-2003 04:16 PM



Advertisments