所以每次我尝试绘制对象列表时都不会绘制它。我在我的课下有绘制方法,似乎一切正常,因为update()
方法下的while循环就像它应该的那样工作。如果它遍历列表并正确打印出来,我如何实现它来读取paintComponent下的相同列表?好像当我尝试它时,它给了我一个空指针异常,这意味着它必须是空的。
更新
public void update(IObservable o, Object arg){
gwp = (GameWorldProxy) o;
gameObjects = gwp.getCollection().getIterator();
while(gameObjects.hasNext()){
GameObject gameObj = (GameObject) gameObjects.getNext();
System.out.println(gameObj);
}
this.repaint();
}
的paintComponent:
public void paintComponent(Graphics g){
super.paintComponent(g);
while(gameObjects.hasNext()){
GameObject gameObj = (GameObject) gameObjects.getNext();
gameObj.draw(g);
}
}