[2735] in java-interest

home help back first fref pref prev next nref lref last post

Re: Repainting delayed

daemon@ATHENA.MIT.EDU (Stephen Harris)
Thu Oct 12 06:39:32 1995

From: sweh@mpn.com (Stephen Harris)
To: java-interest@java.Eng.Sun.COM
Date: Thu, 12 Oct 1995 09:31:59 +0100 (BST)
In-Reply-To: <199510112201.PAA09603@jakarta.Eng.Sun.COM> from "Arthur van Hoff" at Oct 11, 95 03:01:22 pm

> Hi Stephen,

Hi Arthur,
  much appreciate the help.

> Try putting a sleep in there so that the event handler has some time

> 	for (int i = 0 ; i < 10 ; i++) {
> 	    randomly_select_images;
> 	    repaint();
> 	    Thread.sleep(100);
> 	}

Unfortunately this doesn't seem to work.  I'd tried this with a sleep(1000)
and all that resulted was a 10 second delay before the screen updated.
Just in case it was the async loading of images taking too long, I used
Jim's MediaTracker classs (quite neat!), and this improves the drawing of
images, but still doesn't flash symbols :-(

Would it have anything to do with being inside mouseDown() that causes
the problem (ie are repaint() calls suspended until mouseDown() completes?)

Some more details (if you don't mind reading this far...)

  public class game extends java.applet.Applet implements Runnable

I have a Thead running that play()s a sound then sleep(2500) [ effectively
a background noise - the play() lasts around 2 seconds ], and in the main
thread I do inside mouseDown()

      for (i=0;i<10;i++)
      {
        for (j=0;j<num_icons;j++)
        {
          k=Math.random();
          if (k < l)
            selected[j]=!selected[j];
        }
        repaint();
        Thread.sleep(1000);   
      }

The paint() method uses double buffering and calls mypaint() which does

    for (int i=0; i<num_icons;i++)
      if (selected[i])
        g.drawImage(img_lit[i],icon_x[i],icon_y[i], this);
      else
        g.drawImage(img_normal[i],icon_x[i],icon_y[i], this);


Any advice you, or other members of this list, can provide would be most
welcome!

Thanks/rgds
Stephen

PS: I know I should really have made the icon into an object with the various
attributes and a "drawme()" method :-)
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post