is there a way to send the
System.out.println(); to a status window or a text area… using
import javax.swing.JTextArea
???
is there a way to send the
System.out.println(); to a status window or a text area… using
import javax.swing.JTextArea
???
Instead of using System.out.println() you could just use JTextArea.append(), unless I am misunderstanding youe question.
CaseyB
Is it possible to use System.setOut() in an applet?
No to my knowledge you cannot just point a stream at a text area. You can redirect out to a differnt stream but you would have write your own stream type to
take the stramed input and draw it to a text window.
Most browsers however have a console you can turn on that will ctach all Java output if your just trying to see your errors.
Yup yup … here is what I have
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.applet.Applet;
import javax.swing.JTextArea;
in my main class
then later on i have
private void setupStatus( JTextArea ta ) {
// Setup Status Area.
setupStatus( status );
// -------- JTextArea status --------
if ( null == ta ) {
status = new StatusArea( 5, 20 );
}
else {
status = ta;
}
// JScrollPane pane = new JScrollPane();
// pane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
// );
// pane.setHorizontalScrollBarPolicy(
// JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
//
// pane.getViewport().add( status );
// this.add( pane );
And then the seperate StatusArea Class
then later on
public class StatusArea extends JTextArea {
public StatusArea(int rows, int columns) {
super( rows, columns );
setBackground( new Color( 255, 255, 203 ) );
setEditable( false );
setLineWrap( true );
setWrapStyleWord( true );
}
// Overwriting the default Append class such that it scrolls to the
// bottom of the text. The JFC doesn’t always rememeber to do that.
public void append( String str ) {
super.append( str );
setCaretPosition( getText().length() );
}
}
now i just need to be able to put my text in there.
Which i am having trouble doing
If I understand what you are trying to get at, then it should be like this:
try
{
soemthing;
}
catch(SomeException e)
{
status.append(e.toString());
}
or if at some point you would do a
System.out.println(someIntVariable);
just change it to
status.append(Integer.toString(someIntVariable));
CaseyB
What’s the point of that setupStatus( status ); method call in the beginning of setupStatus? Doesn’t that just keep on calling setupStatus indefinitely (and cause a StackOverflowError)?
Well funny thing is that it actually did. This has since been removed as I relized this and was calling it further up in my code 
The joys of learning 