日期:2014-05-20 浏览次数:21290 次
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
}
}
public void componentShown(ComponentEvent e) {
if (shouldShow()) {
synchronized (getTreeLock()) {
if (peer != null) {
peer.show();
}
}
}
}
------解决方案--------------------
只要窗体显示、布局、位置稍有改变都会触发...