62,614
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
}
}
public void show() {
if (!visible) {
synchronized (getTreeLock()) {
visible = true;
mixOnShowing();
ComponentPeer peer = this.peer;
if (peer != null) {
peer.show();
createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
this, parent,
HierarchyEvent.SHOWING_CHANGED,
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
if (peer instanceof LightweightPeer) {
repaint();
}
updateCursorImmediately();
}
if (componentListener != null ||
(eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
ComponentEvent e = new ComponentEvent(this,
ComponentEvent.COMPONENT_SHOWN);
Toolkit.getEventQueue().postEvent(e);
}
}
Container parent = this.parent;
if (parent != null) {
parent.invalidate();
}
}
}