简体   繁体   中英

How do I get this to run. I keep on getting a cannot find symbol

I saw this code on this stackoverflow question at Create Java console inside a GUI panel

Whenever I compile the code though I get an error saying it can't find the symbol TextAreaOutputStream. I really want to have this work. I would really appreciate an explanation for why I can't compile this.

 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import java.io.*;

public class GUI{
public static void main( String [] args ) throws InterruptedException  {
    JFrame frame = new JFrame();
    frame.add( new JLabel(" Outout" ), BorderLayout.NORTH );

    JTextArea ta = new JTextArea();
    TextAreaOutputStream taos = new TextAreaOutputStream( ta, 60 );
    PrintStream ps = new PrintStream( taos );
    System.setOut( ps );
    System.setErr( ps );


    frame.add( new JScrollPane( ta )  );

    frame.pack();
    frame.setVisible( true );

    for( int i = 0 ; i < 100 ; i++ ) {
        System.out.println( i );
        Thread.sleep( 500 );
    }
}
}

TextAreaOutputStream isn't a class included in the standard library. The code for it is in that other SO post you referenced. To use it, you'll have to copy/paste that code and compile it along with your class. You might be better off looking around for an existing library that does what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM