> jLabel1 isn't a great name for a variable.
>
[quoted text clipped - 7 lines]
>
> Tom Hawtin
Joseph Gruber wrote:
> This is more of a test so the variable name was left alone.
If you have got a problem with your code, it generally helps if what is
there is as clear as possible.
> I've used
> the javax.swing.Timer and that works perfectly but I need more control
> over when the timer fires. With the Swing Timer the clock lags behind
> every once in a while due to the overhead in the Swing Timer whereas
> the java.util.Timer doesn't.
That's no excuse. You must be in the Event Dispatch Thread (EDT) when
manipulating Swing components. I guess what you are finding is that the
EDT is busy. That's not going to be a good point to break the EDT rule.
Tom Hawtin
Joseph Gruber - 25 Jun 2007 11:40 GMT
> That's no excuse. You must be in the Event Dispatch Thread (EDT) when
> manipulating Swing components. I guess what you are finding is that the
> EDT is busy. That's not going to be a good point to break the EDT rule.
>
> Tom Hawtin
I'm new to Java so pardon me. Can you explain what you mean by the
EDT?
Joseph Gruber - 25 Jun 2007 11:52 GMT
> > That's no excuse. You must be in the Event Dispatch Thread (EDT) when
> > manipulating Swing components. I guess what you are finding is that the
[quoted text clipped - 4 lines]
> I'm new to Java so pardon me. Can you explain what you mean by the
> EDT?
Figured it out :)
For those who may stumble upon this the following webpage helped a
lot: http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
Tom Hawtin - 25 Jun 2007 11:55 GMT
Joseph Gruber wrote:
> I'm new to Java so pardon me. Can you explain what you mean by the
> EDT?
The Event Dispatch Thread (EDT) is the thread that all AWT events
dispatched in. If you run your code as an applet or under WebStart, you
will have multiple EDTs. However, only one EDT will be visible to your code.
Like the vast majority of GUI toolkits, Swing is not multithreaded. You
need to ensure that Swing objects are only used on a single thread (the
EDT). To execute code on the EDT from a non-EDT thread, use
java.awt.EventQueue.invokeLater (or possibly invokeAndWait). This is
what your original example correctly did within the main method.
Tom Hawtin