Although we don't technically require a JTree object in order to create a tree, it
ensures we can always easily access the root of the tree. There are no parameters that
we need to pass when creating a new tree:
$tree = new JTree();
When a new tree is created, we automatically create a new JNode object, which is
known as the root node. The root node is the node to which all other nodes in the
tree can trace their roots.
The first thing we normally do once we have created a tree is add some child nodes.
To do this we will use the JTree addChild() method:
$tree->addChild(new JNode());
When we use the JTree addChild() method, the child isn't necessarily added as a
direct descendant to the root node. Trees use a pointer to determine the current/
working node. When we add a new child node it is added to the present working
node's children. By default the working node is the root node.
The next diagram depicts a tree using the JNode and JTree classes. The root node is
node A??”the root node never changes during the life of the tree.
Pages:
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501