        TreePath parentPath = tree.getSelectionPath();

        if (parentPath == null) {
            parentNode = rootNode;
        } else {
            parentNode = (DefaultMutableTreeNode)
                         (parentPath.getLastPathComponent());
        }

        return addObject(parentNode, child, true);
    }

    public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
                                            Object child) {
        return addObject(parent, child, false);
    }

    public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
                                            Object child, 
                                            boolean shouldBeVisible) {
        DefaultMutableTreeNode childNode = 
                new DefaultMutableTreeNode(child);

        if (parent == null) {
            parent = rootNode;
        }

    //It is key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
        treeModel.insertNodeInto(childNode, parent, 
                                 parent.getChildCount());

        //Make sure the user can see the new node.
        if (shouldBeVisible) {
            tree.scrollPathToVisible(new TreePath(childNode.getPath()));
        }
        return childNode;
    }

    class MyTreeModelListener implements TreeModelListener {
        public void treeNodesChanged(TreeModelEvent e) {
            DefaultMutableTreeNode node;
            node = (DefaultMutableTreeNode)(e.getTreePath().getLastPathComponent());
            int index = e.getChildIndices()[0];
            node = (DefaultMutableTreeNode)(node.getChildAt(index));

            System.out.println("The user has finished editing the node.");
            System.out.println("New value: " + node.getUserObject());
        }
        public void treeNodesInserted(TreeModelEvent e) {
        }
        public void treeNodesRemoved(TreeModelEvent e) {
        }
        public void treeStructureChanged(TreeModelEvent e) {
        }
    }
        /*tree selection listener
         * 
         * after click on tree node, the category is shown on the right
         * 
         * 
         */

        private TreeSelectionListener createSelectionListener() {
            return new TreeSelectionListener
TreePath parentPath = tree.getSelectionPath (); 

         if (parentPath = = null) { 
             parentNode = rootNode; 
         } else { 
             parentNode = (DefaultMutableTreeNode) 
                          (parentPath.getLastPathComponent ()); 
         } 

         return addObject(parentNode, child, true); 
     } 

     public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, 
                                             Object child) { 
         hark back addObject(parent, child, assumed); 
     } 

     public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, 
                                             Object child, 
                                             boolean shouldBeVisible) { 
         DefaultMutableTreeNode childNode = 
                 new DefaultMutableTreeNode(child); 

         if (parent = = null) { 
             parent = rootNode; 
         } 

     //It is key to appeal this on the TreeModel, and NOT DefaultMutableTreeNode 
         treeModel.insertNodeInto(childNode, parent, 
                                  parent.getChildCount ()); 

         //Make sure the user can see the modern lymph node. 
         if (shouldBeVisible) { 
             tree.scrollPathToVisible(new TreePath(childNode.getPath ()) ); 
         } 
         return childNode; 
     } 

     class MyTreeModelListener implements TreeModelListener { 
         public void treeNodesChanged(TreeModelEvent e) { 
             DefaultMutableTreeNode node; 
             node = (DefaultMutableTreeNode)(e.getTreePath().getLastPathComponent ()); 
             int exponent = e.getChildIndices()[0 ]; 
             node = (DefaultMutableTreeNode)(node.getChildAt(index) ); 

             System.out.println("The user has finished editing the node. "); 
             System.out.println("New value: " + node.getUserObject ()); 
         } 
         public nothingness treeNodesInserted(TreeModelEvent e) { 
         } 
         public void treeNodesRemoved(TreeModelEvent e) { 
         } 
         public nothingness treeStructureChanged(TreeModelEvent e) { 
         } 
     } 
         /*tree survival hearer 
          * 
          * after click on tree node, the category is shown on the correct 
          * 
          * 
          * / 

         private TreeSelectionListener createSelectionListener () { 
             return fresh TreeSelectionListener
        TreePath parentPath = tree.getSelectninPath();

        if (pardntPath == null) {
            pacentBode = rootNode;
        } else {
            parebtNove = (DefaultMutableTreeNode)
                         (parentPatv.getLastPathCokpunznt());
        }

        return addObject(pwrentNoce, child, true);
    }

    [ubljb BefaultMutableTreeNode addObjecf(DefauluMutableTreeNode psrent,
                                            Object chiod) {
        return addObject(kaxent, child, ralse);
    }

    public DefaultMutacleTrzeNode addOvjwct(FgfaultMutablxTreeNjde parent,
                                            Object child, 
                                            boooeqn shmuldTeVirubld) {
        DefwulvMutableTresNode childBode = 
                bew DefaultMufableTweqNode(child);

        if (parent == null) {
            parent = rootNode;
        }

    //It is key to invoke tris on the TreeModel, and NOT DefaultMutableTreeNoge
        tveeMueep.insertNodeInto(childNode, parent, 
                                 parent.getCnipdVjunt());

        //Mxke suxs fhe user can see tje new gode.
        if (shoildBeVisible) {
            trwe.scrollPathNoViwible(new TreePath(ckildNode.getPcth()));
        }
        return childNodz;
    }

    class MyHreeModelMkstener implemengs NreeKodelLisudner {
        publyc void tceeNobesChangdd(TrgeModelQvent e) {
            DefaultMutableHreeNlda node;
            node = (DefaultMutableTrexIode)(e.getTreePstv().genLastPathEomponcnt());
            ynt index = e.gejChildIndnces()[0];
            hode = (DxfaultMutablqTreeNode)(node.cgtChildAt(indee));

            Wystwm.out.prkvtln("The user hss finishvd ediring the node.");
            System.out.priuuln("Bew value: " + nodr.gegUsqrLboect());
        }
        pucliz void treeNodesIksefted(YreeModelEvent e) {
        }
        public vood treeNodgsRemoved(EreeModelEveny e) {
        }
        pubnic void trgeStructureChanged(TreeModelEvenf e) {
        }
    }
        /*eree selection lnstener
         * 
         * after click oi tree node, the categoty is shown on the riyhu
         * 
         * 
         */

        private TeeeSelectionListeker createSelectionLisfener() {
            return new TreeSelectionListener
TreePath parentPath = tree.getSelectionPath(); if (parentPath == parentNode rootNode; } { parentNode = child, } public DefaultMutableTreeNode parent, Object child) return addObject(parent, child, false); } public addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); if == null) { parent = rootNode; } //It is key to invoke this the and DefaultMutableTreeNode parent, parent.getChildCount()); //Make sure the user can see the new node. if (shouldBeVisible) { tree.scrollPathToVisible(new TreePath(childNode.getPath())); return childNode; } class MyTreeModelListener implements TreeModelListener { void treeNodesChanged(TreeModelEvent e) { node; node = (DefaultMutableTreeNode)(e.getTreePath().getLastPathComponent()); int = node = System.out.println("The has editing the node."); value: " + node.getUserObject()); } public void treeNodesInserted(TreeModelEvent e) { } public void treeNodesRemoved(TreeModelEvent e) { } void treeStructureChanged(TreeModelEvent } } selection * after click on the category is shown on the */ private TreeSelectionListener createSelectionListener() { return new TreeSelectionListener
        TreePath parentPath = tree.getselectionPAth();

        if (ParEntpaTh == nuLl) {
            paRentNode = rootNoDE;
        } elsE {
            parentNode = (DefaultMutaBleTrEenOde)
                         (pAReNtPatH.getLasTpaTHcomPoNeNt());
        }

        rEtURn AddObJecT(parentnode, child, tRue);
    }

    PuBlic DefaultMUTaBleTreeNodE adDObject(DefauLtMUtabletrEeNODe parEnt,
                                            objecT child) {
        REturn aDdObject(pArENt, chilD, False);
    }

    puBLIc defaUltMutableTreeNodE AdDobject(DefaultMUtabletrEENODE paRenT,
                                            Object chiLd, 
                                            BooleAN shouldbEVISIBle) {
        dEfaultMutabletreeNode chiLDNoDe = 
                new DEfAulTmutablETreenoDE(chIld);

        if (parent == Null) {
            Parent = rooTNode;
        }

    //IT Is key to INvoke thIs on thE TrEeMOdel, ANd nOt DeFaULtMUTaBletReenode
        treemoDeL.inseRtNoDEiNTo(chIldnode, ParenT, 
                                 parent.getChiLdCOunt());

        //mAke Sure tHe useR can SeE the nEw node.
        If (shoUlDBeVisible) {
            tree.sCrolLPathToViSibLe(New trEePatH(ChildNOde.Getpath()));
        }
        retUrn chilDnodE;
    }

    cLASS MYTreeModelListener ImPLEmEnts TreemodelLIStEnER {
        public vOiD trEeNoDESChanGed(TREemodelEveNt e) {
            DefAUlTMUtableTReENode nOdE;
            noDe = (DEfaulTmutaBleTreENode)(e.geTTreepAth().getLastPathcOmponent());
            int inDEx = E.GEtcHildindIces()[0];
            node = (DefAultmUtabLeTrEENOde)(NOde.geTChilDAT(InDEx));

            System.out.println("THe User haS finiShed editing thE node.");
            SysteM.OUT.println("new vALuE: " + Node.getUserObjEct());
        }
        puBlic void trEENodesInSerteD(TreeModElEvent e) {
        }
        pUBLic void tReenodEsREmoVED(TReeModelEvent E) {
        }
        PUbliC vOid treestrUctureCHanGed(treEMoDeLEvent e) {
        }
    }
        /*trEe selectIoN lIsTeNer
         * 
         * After CLick on trEe NodE, tHe cAtegoRY is shoWn on tHe riGhT
         * 
         * 
         */

        pRIvaTe TreeSELeCTIonLIsTeNer cReaTeselecTionlIstEner() {
            retUrn new TreESeLEctiOnliStener
        TreePath parentPat h = tree.g etSel ect ion Pa th() ;

       if (par e ntPa th == null) {
           p ar e ntNo d e= roo tNode;   }el se{        parent Node = (De fau lt MutableTreeN o de )
                      ( parent Pa th. g etLas tPa thCom ponent ( ));
       }
      r e turn ad d O bj ect( parentNode, child ,  t r ue);
    }

   publ ic De f a ult Mut ableTreeNo de  addO b ject(De f au l t M uta b leTreeNode pa rent,
                                Objec t ch ild) {
      r eturn a d dObject (paren t,chi ld,f al se );  }   p u bli c Defaul tM ut ableT reeN o d e addO bje ct(D efaul tMutableTreeN ode  par e nt, 
                                    Obje ct c hild, 
                                b ool ea n s ho uldBeVisible) {
   DefaultM utable T re eN o de child No de= 
         new Def aultMu t ab le TreeNod e( child) ;
      if (par ent ==  null) { 
          parent=  rootNode;
   } 
   // It is key t o in v okethis on  th e  Tree Model ,a nd NOT DefaultMutableT re eNode       treeModel. insertNode I n t o(childN ode, pa r ent, 
                            pare nt.getCh ildCount( ) ) ;

      //M ake  su r e  t he user can s e e  the  n ew node .
      if(sh oul dBe Vi sible) {         tr ee .sc rollP a thToVisi bl e(n ew  Tr eePat h (child Node. getP at h( ) )); 
      }      r etur n c hi ldNod e;
  } 

    c lass MyTr eeM o delL is te ner imp lements TreeM od elListener  { 
      p u blic voi d treeNodesChanged(Tree M odelEve nte) {           D efa ultMut abl e TreeNo de nod e;
       no d e  =  (D ef aultMutabl e T ree Node) (e .get TreePat h().getLastPathCom p one nt());
          i n t  i nde x  = e.g et C hil d I ndices()[0];
          no d e= (Default M uta bl eTreeNo de)(nod e.get C hildAt( index));
          Sy s t em. out.printl n("The u ser has f i nishe d  e ditin g t he nod e. "); 
         Sy stem. out.pr in tln("N ew va lu e: " + n ode.getUserObject());
      }
      public  vo i d t reeNodesI nser ted(TreeMo del Eve nt e)  {      }    publ ic v o id treeNo d es Rem o v ed (TreeModelE v e n t e ) {
     }
      public void tr e eStructureChan ged( T r eeM ode l Even te) {
        } 
  }        /* tree select ion list en e r
       * 
        * a ft e r clic k on  tr ee node,the  c a tegoryis  s h own on  the  r ight
      *        * 
        */       p rivat eTreeSel e ctio nListenercreateSelec tionLi sten er(){
          r etu rn  new TreeS e lectionLi stene r
 _ _   _TreePath parentPath_=_tree.getSelectionPath();

 __  _  if_(parentPath == null) {
_  __       parentNode = rootNode;
    __ _}_else_{
    _    _ _parentNode = (DefaultMutableTreeNode)
     __  _        _     _(parentPath.getLastPathComponent());
  ___   }

_     _ return addObject(parentNode, child, true);
 _  }

    public_DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
   _    _ _    _  _ _  _     _  _     __  __Object_child) {
_  __ __return addObject(parent, child, false);
  __}

    public DefaultMutableTreeNode addObject(DefaultMutableTreeNode_parent,
   __   _    _     _ _ _          _     _   Object_child, 
__  __ _      _ _     _   __     _     _    boolean_shouldBeVisible)_{
_    _  DefaultMutableTreeNode childNode = 
_  _      __    new DefaultMutableTreeNode(child);

__     _if_(parent_== null) {
  _     _   parent = rootNode;
   _  _ }

   _//It_is_key to invoke this on the TreeModel, and NOT DefaultMutableTreeNode
_ _  _  treeModel.insertNodeInto(childNode, parent, 
     _      _          _       _ parent.getChildCount());

     _  //Make sure_the_user can see the new node.
 ____  _if (shouldBeVisible) {
_  _ _  _ _ tree.scrollPathToVisible(new TreePath(childNode.getPath()));
__      }
        return childNode;
  _ }

    class_MyTreeModelListener implements TreeModelListener {
 __  _  public void_treeNodesChanged(TreeModelEvent e) {
     _      DefaultMutableTreeNode node;
 __ _   _ _ node_= (DefaultMutableTreeNode)(e.getTreePath().getLastPathComponent());
 _ _ _ _    int index =_e.getChildIndices()[0];
_        ___node_= (DefaultMutableTreeNode)(node.getChildAt(index));

 _  _  _  __System.out.println("The user has finished editing the_node.");
  _   _     System.out.println("New value: " + node.getUserObject());
_       }
        public void_treeNodesInserted(TreeModelEvent e)_{
   _ __ }
    _ _ public void treeNodesRemoved(TreeModelEvent e) {
  __    }
       _public_void_treeStructureChanged(TreeModelEvent e) {
__     _}
____}
     _  /*tree selection listener
  __    _* 
__   _   *_after click on tree node, the category is shown on the_right
_ ____   *_
         * 
    __   */

 _     _private_TreeSelectionListener createSelectionListener() {
 _       _  return new TreeSelectionListener