Is this a situation where text is sent to the JTextArea one line at a time, but the lines only actually appear in the text area all at once at the end of program execution?
If so, it is possible that as soon as you issue the command to display a line of text in the text area, then your code starts churning away on the next task, and it hogs the CPU, and nothing gets displayed until the CPU is free at the end. Just a guess.
If this is so, then depending on your program design, the solution would probably involve the appropriate use of threads, or Swing Timers, or something like that.
knzo lobos wrote:thanks for aswer
well thi is not because of the pc
Please re-read what Fred wrote as he never said that this was because of the pc. It's possibly because of a threading issue, and I strongly agree with him. Again, use a background thread such as a SwingWorker. Please read up on Concurrency In Swing.
This does not indicate a problem or limitation with your PC, it is about how your program design affects the allocation of your computer's resources.
If you research threads a bit, and maybe give us a better idea of your program design, probably it could be sorted out pretty easily.
p.s. as Pete said.
Also, if you find the Sun java materials on Concurrency a little difficult, the following article provides a decent introduction. Just be aware that the article is kind of old, and makes reference to deprecated mathods, such as stop(). But the eplanation of the basic ideas is good, and would make the more uptodate material in the Java Tutorial easier to understand
As I see it, the issue is not so much that your code needs to execute in a thread, but that the the code that updates the text area needs to happen in a different thread than the continuously running part of the code.
I don't totally understand what is going on with your program, but it appears that you have not separated into separate threads those parts of the code that are in conflict for CPU time,
It's not an easy topic to understand, it may require some research of the basic concepts of multithreading for you to appreciate what I am saying. Anyways, I am not an expert in threads, maybe someone else can describe it better.
OK, I have a suggestion. Start from scratch and try to design a very simple prototype that duplicates the problem without all the bells and whistles that your existing program has. Maybe your prototype will involve a very simple continuously running loop that does some computations and outputs results to the JText area. Do it without using any special thread programming or run() method.
Once you have done that give an effort to fixing the problem in the simple situation, that will give you the idea how to solve the problem in your console simulator program. It will also be easier for us to help you with the prototype than with your console program.
p.s. OK Rob has a similar idea, he snuck in ahead of me.