I want to use a thread,
No you don't. You can get into no end of trouble by threading Swing® components wrongly; they are not thread‑safe.spike mtz wrote:. . . I want to use a thread, not a Timer component. . . .
and crashing...
Norm Radder wrote:
and crashing...
Please copy the full text of the error message and paste it here. It has important info about the error.
Norm Radder wrote:The while loop has nothing to slow its execution down. It will loop many thousands of times in less than a second and be calling the invokeLater method each time. That will cause congestion in the code.
The loop should not call invokeLater so frequently. It should be called about one time for each change in the least significant digit it displays. If the display shows 1/10 of seconds, then call it about every .1 second.
spike metzer wrote:
How can i do this?
Henry Wong wrote:
spike metzer wrote:
How can i do this?
The easiest way would be to use some sort of flag. Don't call invokeLater() to add a task, until the previous one has completed first. This way, you don't get a runaway effect, where the EDT has thousands of tasks to do, and other tasks (like reading the keyboard/mouse) has to wait their turn.
Henry
There are three kinds of actuaries: those who can count, and those who can't.
I know there are some people who use this website who disbelieve anything about Swing methods being thread‑safe.Piet Souris wrote:. . . Note that that tutorial claims that the 'setText' method is thread safe, so you could update the label directly. . . .
It can cause the display to hang because the painting cannot be completed in the time the thread is awake.. . . what is unreliable about Thread.sleep?
Piet Souris wrote:@Stephan
what is unreliable about Thread.sleep?
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|