jtcy
asked on
TreeNode *urgent*
Can someone gimme the TreeNode codes cuz I need to build a tree. I need the class that has method such as isLeaf, insertChild or watever etc....pls~ Thanks~
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I need to implement my own.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have my class extends DefaultMutableTreeNode and above I have it import java.lang.*; it says cant resolve the class~
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
actually i just need methos like addChild, isLeaf, getChildAt, etc. Whether or not it's my own is not matter but if i could implement TreeNode myself with just few of these methods would be a better choice.
> but if i could implement TreeNode myself with just few of these methods would be a better choice.
Why exactly, surely using an already existing class would be preferable?
Why exactly, surely using an already existing class would be preferable?
ASKER
i donno if i am allowed to use them....anyway, i am trying to use them. Um...which package does DefaultMutablewatever class from? I try importing java.lang.*; still cant find it
addChild, isLeaf, getChildAt and many more methods are already available in DefaultMutableTreeNode.
It is found at
javax.swing.tree.DefaultMu tableTreeN ode
the package that you are suppose to import is
import javax.swing.tree.DefaultMu tableTreeN ode;
javax.swing.tree.DefaultMu
the package that you are suppose to import is
import javax.swing.tree.DefaultMu
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> which package does DefaultMutablewatever class from?
see my original comment:
javax.swing.tree.DefaultMu tableTreeN ode
see my original comment:
javax.swing.tree.DefaultMu
ASKER
objects, which class should ur treeNode extend?
ASKER
does arrayList works like vector where we don need to keep its element offset? and its size gets incremented automatically?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how do i do square root in java?
Math.sqrt(<double>);
ASKER
if a variable is int, says int distance, can i do :
distance = Math.sqrt((double) distance); ??
distance = Math.sqrt((double) distance); ??
yes you can
distance = (int)Math.sqrt((double) distance);
distance = (int)Math.sqrt((double) distance);
ASKER
Okay, got a big trouble. For a given root node, i need to traverse it down and for every children of it, if it is a leaf node, then call a function called "evaluate(thisNode)", else just keep on traversing till its end. How can I do that?
Here is the example, using which you can traverse the whole tree....
http://javaalmanac.com/egs/javax.swing.tree/GetNodes.html?l=rel
http://javaalmanac.com/egs/javax.swing.tree/GetNodes.html?l=rel
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
objects, could u write getParents for me please?~ i am stuck of it.
no longer interested in our input?
OK.
OK.
getParent could be a TreeNode.
public TreeNode getParent(TreeNode node)
{
return node.getParent();
}
public TreeNode getParent(TreeNode node)
{
return node.getParent();
}
ASKER
will this work? an infinite recursion?
jtcy, are you doing a "spring clean up" of all your open Q's?
Nevertheless, thanks for awarding our efforts.
Nevertheless, thanks for awarding our efforts.
ASKER