Hello! Please explain this. I am sending it for second time. I am stuck for last three days and I have no clues about it. See this part of the prgram, I have attached comments in this if loop: if (node instanceof Box && event1.getClickCount()==2 ) I am facing a very peculiar problem: I am trying to detach a branchgroup from a transformgroup. When I use removeChild(int) method of TransformGroup, i can detach the Branchgroup but when I use detach() method of BranchGroup, I can't. it is also not throwing any exception but there is no effect of using detach() method. I really want to use detach() method because with this i can identify a particular branchgroup, which is not possible with removeChild(), as I am attaching BranchGroups randomly every time I run the application, so their order wil be different. Can somebody gives me any tips. I am attaching behavior class with this mail for quick reference. thanks __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
class slbehavior extends Behavior { private TransformGroup targetTG; private BranchGroup scene; private Canvas3D canvas; public static int count=0; public static Point3d cg[]=new Point3d[2]; public BranchGroup bgbox,bgcone,bgcyl,bgsph; slbehavior (TransformGroup targetTG,Canvas3D canvas, BranchGroup scene) { this.targetTG=targetTG; this.scene=scene; this.canvas=canvas; } public void initialize() { this.wakeupOn(new WakeupOnAWTEvent(MouseEvent.MOUSE_CLICKED)); } WakeupOnAWTEvent trigger = new WakeupOnAWTEvent(MouseEvent.MOUSE_CLICKED); public void processStimulus (Enumeration criteria) { PickShape shape=null; PickObject obj = new PickObject(canvas,scene); if ( obj != null ) { AWTEvent myEvent[] = trigger.getAWTEvent(); int xpos = 0; int ypos = 0; MouseEvent event1=null; try { event1 = (MouseEvent) myEvent[0]; } catch (ArrayIndexOutOfBoundsException a){} if ( event1 != null ) { xpos = event1.getX(); ypos = event1.getY(); System.out.println(xpos + " " + ypos); } SceneGraphPath closest = obj.pickClosest(xpos, ypos); if ( closest != null ) { Primitive myShape=null; try { Node node = closest.getNode(1); int nodeCount = closest.nodeCount(); System.out.println(nodeCount); if (node instanceof Primitive) { myShape = (Primitive) node; } bgbox = new BranchGroup(); bgbox.setCapability(BranchGroup.ALLOW_DETACH); bgbox.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); bgbox.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); bgcyl=new BranchGroup(); bgcyl.setCapability(BranchGroup.ALLOW_DETACH); bgcyl.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); bgcyl.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); bgcone=new BranchGroup(); bgcone.setCapability(BranchGroup.ALLOW_DETACH); bgcone.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); bgcone.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); bgsph=new BranchGroup(); bgsph.setCapability(BranchGroup.ALLOW_DETACH); bgsph.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); bgsph.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); if (myShape!=null && event1.getClickCount()==1) { System.out.println(count); cg[count++] = (Point3d)myShape.getUserData(); if (count==2 && node instanceof Sphere) { LineArray la=new LineArray(2,LineArray.COORDINATES); la.setCoordinates(0,cg); Shape3D shapesph = new Shape3D(la); bgsph.addChild(shapesph); System.out.println("Number of Children of TargetTG before bgsph is attached to it:" + targetTG.numChildren()); targetTG.addChild(bgsph); System.out.println("Number of Children of TargetTG after bgsph is attached to it:" + targetTG.numChildren()); count=0; } if (count==2 && node instanceof Box ) { LineArray la=new LineArray(2,LineArray.COORDINATES); la.setCoordinates(0,cg); Shape3D shapebox = new Shape3D(la); bgbox.addChild(shapebox); System.out.println("Number of Children of TargetTG before bgbox is attached to it:" + targetTG.numChildren()); targetTG.addChild(bgbox); System.out.println("Number of Children of TargetTG after bgbox is attached to it:" + targetTG.numChildren()); count=0; } if (count==2 && node instanceof Cylinder ) { LineArray la=new LineArray(2,LineArray.COORDINATES); la.setCoordinates(0,cg); Shape3D shapecyl = new Shape3D(la); bgcyl.addChild(shapecyl); System.out.println("Number of Children of TargetTG before bgcyl is attached to it:" + targetTG.numChildren()); targetTG.addChild(bgcyl); System.out.println("Number of Children of TargetTG after bgcyl is attached to it:" + targetTG.numChildren()); count=0; } if (count==2 && node instanceof Cone) { LineArray la=new LineArray(2,LineArray.COORDINATES); la.setCoordinates(0,cg); Shape3D shapecone = new Shape3D(la); bgcone.addChild(shapecone); System.out.println("Number of Children of TargetTG before bgcone is attached to it:" + targetTG.numChildren()); targetTG.addChild(bgcone); System.out.println("Number of Children of TargetTG after bgcone is attached to it:" + targetTG.numChildren()); count=0; } } // end of myshape!=null else { System.out.println("No Primitive is being Picked Up"); } if (node instanceof Box && event1.getClickCount()==2 ) { System.out.println("Touched a Box"); System.out.println("Number of Children of TargetTG before bg is detached from it:" + targetTG.numChildren()); //targetTG.removeChild(6); // working well, but I don't need it bgbox.detach(); //doesn't work, no clue, I need it System.out.println("Number of Children of TargetTG after bg is detached from it:" + targetTG.numChildren()); } if (node instanceof Cylinder && event1.getClickCount()==2 ) { System.out.println("Touched a Cylinder"); System.out.println("Number of Children of TargetTG before bg is detached from it:" + targetTG.numChildren()); bgcyl.detach(); System.out.println("Number of Children of TargetTG after bg is detached from it:" + targetTG.numChildren()); } if (node instanceof Cone && event1.getClickCount()==2 ) { System.out.println("Touched a Cone"); //Box box=(Box)node; //Point3d x = (Point3d)box.getUserData(); System.out.println("Number of Children of TargetTG before bg is detached from it:" + targetTG.numChildren()); bgcone.detach(); System.out.println("Number of Children of TargetTG after bg is detached from it:" + targetTG.numChildren()); } if (node instanceof Sphere && event1.getClickCount()==2 ) { System.out.println("Touched a Sphere"); System.out.println("Number of Children of TargetTG before bg is detached from it:" + targetTG.numChildren()); bgsph.detach(); System.out.println("Number of Children of TargetTG after bg is detached from it:" + targetTG.numChildren()); } }//end of try catch (ArrayIndexOutOfBoundsException a) { System.out.println("Exception Loop..."); } }// end of closest!=null else { System.out.println("scenegraph path is null..."); } }//end of obj!=null this.wakeupOn(trigger); } }