Hello, I have built a GUI for the world of Zuul, the input can be taken by pressing buttons and enetering text commands. the output is both a change of images and text output using System.out.println().
When I press the directions buttons, the central image changes correctly. but the script response appears in the standard output window, I dont know how to make it appear on my GUI text window!
Is there a standard way to make any output from System.out.println() to appear on a certain JTextArea ? or do I have to pass all the output as a String and use (JTextArea object).setText(String text)?
this is the code i am using in the Interface class to make the text area:

//the o/p text field, the results from the i/p and the possible commands 
        actionTextArea = new JTextArea();
        actionTextArea.setFocusable(false);  //no entry from users
        actionTextArea.setRows(10); 
        actionTextArea.setLineWrap(true);        
        JScrollPane scrollActionTextPane = new JScrollPane(actionTextArea);
        inOutText.add(scrollActionTextPane, BorderLayout.CENTER);

        where inOutText is:
        inOutText.setLayout(new BorderLayout());

Thanks

Recommended Answers

All 4 Replies

You need to implement ActionListener and implement actionPerformed() to accept your button click event. Inside the method, you could use setText() to your text area object. Please refer to oracle link.

isnt it possible to redirect all the CMD output to a JTextArea without doing with for each event?

There are solutions using PipedOutputStream/PipedInputStream. Basically you re-direct System.out and System.err to a piped stream, then in a separate thread read from the pipe and put the text into your JTextArea. Google will find you a few examples; most have extra stuff you may not need (eg handing System.in as well), but they mostly share the same simple few lines of code to achieve the actual redirection.

thanks foe the answer!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.