我试图通过这样做来生成未知数量的按钮:
for (int i = 0; i < itemsList.size(); i++) {
final String item = itemsList.get(i);
TButton button = new TButton("" + item, 8, 415 + (25 * i), 90, 25) {
public void doAction() {
System.out.println("Item: " + item);
}
};
this.buttons.add(button);
}
for (TButton button : buttons) {
this.framework.add(button);
}
但是该框架不接受具有相同名称的多个按钮,因此我收到错误消息。
我可以为每个按钮生成随机/唯一名称吗?
错误:
Exception in thread "main" java.lang.IllegalStateException: gtge.TestGame$1@32301b86 [UIName=Button, bounds=8,415,90,25] [text=Plante] already reside in another container!!!
at com.golden.gamedev.gui.toolkit.TContainer.add(Unknown Source)
at com.golden.gamedev.gui.toolkit.FrameWork.add(Unknown Source)
at gtge.TestGame.update(TestGame.java:78)
at com.golden.gamedev.Game.startGameLoop(Unknown Source)
at com.golden.gamedev.Game.start(Unknown Source)
at com.golden.gamedev.GameLoader.start(Unknown Source)
at gtge.TestGame.main(TestGame.java:96)