BufferStrategy vs DIY Double Buffering in JFrame(JFrame 中的 BufferStrategy 与 DIY 双缓冲)
问题描述
到目前为止,我已经通过创建和 Image 完成了双缓冲,使用其关联的 Graphics 对象将我想要的内容绘制到该 Image 上,然后使用 paint 方法的 Graphics 对象将该 Image 绘制到屏幕上.最近,我了解了 BufferStrategy 类及其用途.我想知道这两种方法的优缺点是什么.
我不认为我的问题很清楚.我想知道 DIY 方法和 BufferStrategy 的优缺点,以及何时应该使用其中一种.
我一直使用默认的 BufferStrategy
得到很好的结果,但要小心
- 始终在 EDT 上构建 GUI 组件
- 切勿从除 EDT 之外的线程中绘图
这个优秀的例子 必须 双缓冲,因为它在初始线程而不是 EDT.相比之下,这个相当繁忙的 示例 仅依赖于 repaint()
调用以响应 Swing Timer
.除了 composite,我很少需要屏幕外缓冲区.最后,这篇教程文章提供了更多指导.p>
Until now, I've done double buffering by creating and Image, drawing what I wanted to that Image using its associated Graphics object then draw that Image to the screen using the paint method's Graphics object. Recently, I learned about the BufferStrategy class and its uses. I was wondering what are the pros and cons of the two methods.
EDIT: I dont't think I made my question very clear. I wanted to know the pros/cons of both the DIY method and the BufferStrategy and when, if ever, I should use one or the other.
I've always had good results using the default BufferStrategy
by being careful to
- Always construct GUI components on the EDT
- Never draw from a thread except the EDT
This excellent example must double buffer because it draws continually on the initial thread rather than the EDT. In contrast, this fairly busy example relies on nothing more than repaint()
called in response to a Swing Timer
. I rarely need an offscreen buffer except for a composite. Finally, this tutorial article offers more guidelines.
这篇关于JFrame 中的 BufferStrategy 与 DIY 双缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JFrame 中的 BufferStrategy 与 DIY 双缓冲


- Eclipse 的最佳 XML 编辑器 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 转换 ldap 日期 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01