repaint为什么执行了两次?
int i; //记录重绘次数
public void display(Shape shape,Ground ground){
System.out.println("GamePanel's display begin");
this.shape = shape;
this.ground = ground;
repaint();
System.out.println("GamePanel's display end");
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
if(shape !=null && ground != null){
System.out.println(i++);
shape.drawMe(); //此方法会打印Shape's drawMe
ground.drawMe(); //此方法会打印Ground's drawMe
}
}
打印结果:
GamePanel's display begin //第一次调用display
GamePanel's display begin
0
Shape's drawMe
Ground's drawMe
1
Shape's drawMe
Ground's drawMe
GamePanel's display begin //第二次调用display
GamePanel's display end
2
Shape's drawMe
Ground's drawMe
GamePanel's display begin //第三次调用display
GamePanel's display end
3
Shape's drawMe
Ground's drawMe
display()是由其它类不停调用的,从打印结果里能看出,display里的repaint第一次调用的时候连续重绘了两次,以后就正常了,这是为什么呢??
...全文
相关推荐
Graphics 与 repaint 方法
"Graphics 与 repaint 方法" Graphics 与 repaint 方法是图形编程中两个非常重要的概念。
Hill no repaint+Arrows1_repaint_hill_
ex4文件是编译后的可执行版本,而.mq4文件则是源代码,允许用户查看和编辑指标的内部逻辑。2.
JavaScript中的Repaint和Reflow用法详解
本文将深入探讨JavaScript中的Repaint和Reflow概念,这两个术语与浏览器渲染网页的过程密切相关。在前端开发中,避免不必要的Repaint和Reflow操作能显著提升页面性能。首先,让
有关javascript的性能优化 (repaint和reflow)
本文将深入探讨两个关键概念:repaint(重绘)和reflow(渲染),以及如何通过理解它们的工作原理来提升JavaScript的执行效率。
100% Non Repaint Forex Scalping Indicator_repaint_nonrepaint_Fo
100% Non Repaint Forex Scalping Indicator" 是一款专为外汇交易者设计的指标,旨在提供无重复绘制(non-repaint)的交易信号,适用于所有货币对和任何时间框架


Java SE
