java清空画布,java图形重绘方法实际上是如何工作的

I've just started working with java 2d graphics applications, on my studies repaint is redrawing our graphics wasting a lot of resources.

but I want to know what repaint is, does and how to use it efficiently, thread safely and fast for many movable dynamic objects on my canvas?

解决方案

repaint makes a request to the RepaintManager to paint part or all of a component. The RepaintManager will decide what and how much will be painted, possible consolidating repaint requests into as small a number of updates as possible (so repeatedly calling repaint could actually slow your paint process).

The RepaintManager then pushes a paint event onto the Event Dispatching Thread. This ensures that the paint event is handle within the context of the EDT.

There are many possible solutions for improving speed and resource management when it comes to painting in Swing.

You could consider implementing your own double buffering strategy, painting your updates to an off screen buffer and when ready, switching to the active buffer, which will get painted.

This means that the paint is quick as all the work has already being done (presumably in a background thread).

For examples...

You could also take a look at Passive vs. Active Rendering, but I'd be very sure that you know what you're getting yourself in for...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值