Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is double buffering (in java) possible with awt? Currently, I'm aware that swing should not be used with awt, so I can't use BufferStrategy and whatnot (I already have some code written in awt that I don't want to rewrite in swing).

If double buffering is possible with awt, do I have to write the buffer by hand? Unlike swing, awt doesn't seem to have the same built-in double buffering capability.

If I do have to write the code by hand, is there a good tutorial to look at? Or is it just easier/advisable for a novice programmer to use swing instead?

Sorry about the multi-step question. Thanks for your time :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
351 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is easily answered on the web. Just search for "double buffer awt" and you'll find LOTS of examples. You can even see an old example I wrote myself in 1998 in Java 1.0 AWT. You just need to instantiate your own Graphics object and draw to an Image, then blit that image into a canvas. Here's the key bit of code in my example:

  public void paint(Graphics g) {
    if (doubleBuffer) {
      paintSky(top.gBuf);
      g.drawImage(top.buf, 0, 0, this);
    } else {
      paintSky(g);
    }
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...