gpt4 book ai didi

java - java 是否将多个 repaint() 调用合并为一个 repaint() ?

转载 作者:行者123 更新时间:2023-12-02 08:39:24 27 4
gpt4 key购买 nike

我每秒收到数百个事件,持续几秒钟,每个事件都会更新我的模型。如果我在每个事件之后在 invokeLater() 内部调用 repaint() ,那么 repaint 每秒会被调用数百次吗?它是否足够聪明,能够意识到它有 500 个备份的 repaint() 并且它只需要执行 1 件事?我不知道事件何时会暂停,但我只想以合理的速度更新 UI。我可以实现一个持续更新的 future,直到有足够长的暂停,比如 500 ms,但如果 java 已经这样做了,那我为什么要这么做呢?

最佳答案

文档是很好的信息来源。

来自repaint()的javadoc :

Note: For more information on the paint mechanisms utilitized by AWT and Swing, including information on how to write the most efficient painting code, see Painting in AWT and Swing.

来自Painting in AWT and Swing

The program invokes repaint() on the component, which registers an asynchronous request to the AWT that this component needs to be repainted.

The AWT causes the event dispatching thread to invoke update() on the component.

NOTE: If multiple calls to repaint() occur on a component before the initial repaint request is processed, the multiple requests may be collapsed into a single call to update(). The algorithm for determining when multiple requests should be collapsed is implementation-dependent. If multiple requests are collapsed, the resulting update rectangle will be equal to the union of the rectangles contained in the collapsed requests.

关于java - java 是否将多个 repaint() 调用合并为一个 repaint() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61473554/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com