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 双缓冲
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
