Here's a trick I sometimes use to see what's getting repainted.  I add a
button that calls a "snow" method on the JPanel subclass or whatever
you're using for your canvas:

 public void snow() {
        float snowFract = 0.25f;
        Random rand = new Random();

        int width = getWidth();
        int height = getHeight();
        System.out.println("## Snowing " + width + " x " + height );

        Graphics2D g2 = (Graphics2D) getGraphics();
        g2.setColor( Color.red);
        for (int i=0; i < width; i++)
            for (int j=0; j < height; j++) {
                if (rand.nextFloat() < snowFract)
                    g2.drawLine( i, j, i, j);
            }
    }

This covers your canvas in random red dots, intentionally bypassing the
RepaintManager.  Then when you interact with your application, you can
see what gets updated.  This won't help you if you're wasting time
updating the entire backing buffer, though.

I know there's a DebugGraphics class (see API docs) that in theory you
could use to accomplish something similar, but I don't think it works
with Java2D.

-David


David Kavanagh wrote:

>In general terms, I'd say this;
>- Draw in to an offscreen buffer
>- your paint() method should simply blit the buffer to the screen
>- issue repaint() after each draw you do and let awt handle the updating of the
>screen. It will collapse multipe repaint requests if they are too frequent.
>(from what I remember)
>
>

===========================================================================
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