Tim Huntington wrote:
>
> I would really appreciate suggestions from anyone on how to structure a
> program to move a large number of small objects slowly around on the
> screen-- i.e. "How would you do it?" (I know how I would do it--I've done
> it, and it doesn't work very well).

You should override update to only invoke paint; otherwise, it
will always clear the background first.  Then just move all your
drawing code to paint (you could put it all in update, but paint
is more standard).

Another thing to consider is doing all your drawing to an off-screen
BufferedImage (in the simulation thread).  Then all paint has to do
is dump that image to the display.  In that case you should turn
off double buffering in the component to avoid an extra copy.
You will have to use some coordination mechanism to let paint know
that it's ok to use the image (that it's not currently being
updated).  One way would be to use a reference to the image that
paint can check - if it's non-null, paint it.  Then set it back
to null when paint's finished so the simulation side can update it.
(You still invoke repaint to trigger paint, but the simulation
doesn't know when that will happen, so it can just go on merrily
updating its state, only refreshing the image contents as needed.)

  simulation                            paint
     loop                                  if reference non-null
        update simulation state               draw image
        if image reference null               clear reference
            update image
            set reference
            invoke repaint
     endloop

This is a somewhat more modular approach, and lets you separate
the model, image compositing, and display update.


---------------------------------------------------------------------
Kevin Weiner    FM Software    Phone 610-997-3930    Fax 509-463-7655

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to