After importing java.awt.event.*, I’ve added a component listener to a class extending GCanvas with the following code:
public NameSurferGraph() {
addComponentListener(this);
nameList = new ArrayList<NameSurferEntry>();
}
public void componentHidden(ComponentEvent e) { }
public void componentMoved(ComponentEvent e) { }
public void componentResized(ComponentEvent e) { update(); }
public void componentShown(ComponentEvent e) { }
public void update() {
removeAll();
drawBackground();
if (nameList.size()>0) {
for (int i=0; i<nameList.size(); i++) {;
drawLineForOneName(i);
}
}
}
But when I call a method on it from another class, nothing happens.
public NameSurferGraph graph = new NameSurferGraph();
public void graphName(String name) {
entry = database.findEntry(name);
graph.addEntry(entry);
graph.update();
}
Any ideas about what I might be doing wrong?
As you don’t provide enough code, I can only guess:
Your call to
removeAll();removes all elements fromnameList, so theifstops you from entering the loop (even if it did not, the loop body will be executing 0 times as the size of an empty collection is 0)