if we select cone in ComboBox,the Applet draws a cone in the Canvas,if we select ColorCube in the same ComboBox,the Applet draws a ColorCube in the Canvas.
Maybe it’s easy,i am a beginner .
thanks for your post!
huh, nobody answers?
hi, since nobody answer, i’ll try, but i’m not very experienced either, so i hope what i say is right.
what you need:
- a onComboChange(…) method
- a TG or BG with capabilities ALLOW_CHILDREN_WRITE and ALLOW_CHILDREN_EXTEND
- the corresponding Cube & Cone nodes.
Then, simply (pseudo-code):
void init() {
Group myRoot = new BranchGroup();
myRoot.setCapability(...);
myCube = makeCube();
myCone = makeCone();
}
void onComboChange(...) {
myForm = (myCube or myCone)
if (currentForm == null)
myRoot.insertChild(myForm, 0);
else
myRoot.setChild(myForm, 0);
currentForm = myForm;
}
hmm… should work. shouldn’t it?
Maybe it works well,i did not try .
Fortunately,I found a way to solve this problem.
it works in such way:
BranchGroup parent_Group=new BrahcnGroup();
praent_Group.setCapability(BranchGroup.ALLOW_DETACH);
and some other capability:
praent_Group.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
…
then,
before you add child Group,clear up the parent_Group
parent_Group.removeChild(index);
last,
add you child Group
parent_Group.addChild(child_Group)