[2721] in java-interest
Re: Repainting delayed
daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Wed Oct 11 20:07:39 1995
Date: Wed, 11 Oct 1995 15:01:22 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: sweh@mpn.com
Cc: java-interest@java.Eng.Sun.COM
Hi Stephen,
> I'm getting there slowly....
>
> In this game I'm writing, if a certain object is pressed I want to
> make a number of other icons flash. Now, I have background gif and
> over the top of this I paint 26 other small gifs. If a selector is
> true then I paint version A, else I paint version B.
>
> The problem I have is that I want the gifs to flash 10 times (say)
> eg
> for (i=0;i<10;i++)
> {
> randomly_select_images;
> repaint()
> }
>
> This is being done inside the mouseDown() method. Unfortunately the
> repaint() isn't being down until after the 10 selections so all I see
> is the final one I want, and not the 9 intermediate selections.
>
> Can anyone advise on a better way of doing this? Maybe a seperate
> thread that acts when a variable is set in mouseDown ?
You need to decide how many times you want it to flash per second.
The way you wrote that loop on an infinitely fast computer won't
show anything on the screen because the images would fly by faster
then the screen refresh rate.
Try putting a sleep in there so that the event handler has some time
to repaint the screen. For example, this should give you about 10 frames
per second:
for (int i = 0 ; i < 10 ; i++) {
randomly_select_images;
repaint();
Thread.sleep(100);
}
Have fun,
Arthur van Hoff
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com