0

I have two java classes. One is a GUI class that calls the second one responsible for detecting words in a document. The second class outputs the keyword in the console. Is there a way to redirect whatever first class outputs to the console to TextArea in GUI class?

To sum up, I have plenty of System.out.println(...) in class one and want to output all of that using my GUI class in a TextArea.

  • Return a string and then append it to your TextArea, – PM 77-1 Feb 05 '18 at 14:19
  • I have plenty of those Strings. – dsafas fsafasfsa Feb 05 '18 at 14:22
  • Return an array of Strings. – PM 77-1 Feb 05 '18 at 14:24
  • This wouldn't be really accurate. We would collect say 200 strings and then return them all at once rather than print them dynamically as a program runs. I'm scanning documents and want to output something while we're scanning the document, not after all documents are scanned. – dsafas fsafasfsa Feb 05 '18 at 14:26
  • [Edit] your question and put **all** requirements there, as well as your sample code. – PM 77-1 Feb 05 '18 at 14:28
  • Here https://stackoverflow.com/q/48577313/312172 is an example how to do it. Note that it wasn't the question at hand, so the answer is in the question, not in the answer. :) – user unknown Feb 05 '18 at 14:39
  • 1
    `The second class outputs the keyword in the console.` Why? Doesn't sound like a very good design. Replace the System.out.println(...) statements with textArea.append(...) statements. But if you don't want to change the design then you can use the [Message Console](https://tips4java.wordpress.com/2008/11/08/message-console/) – camickr Feb 05 '18 at 15:13
  • @camickr - sounds like really tight coupling, doesn't it? – PM 77-1 Feb 05 '18 at 15:16
  • When I do textArea.append and pass it back to the gui it is all displayed in one go. I want it to be sequentially displayed like in a normal console window. – dsafas fsafasfsa Feb 06 '18 at 09:00

0 Answers0