Link to home
Start Free TrialLog in
Avatar of jtcy
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
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtcy
jtcy

ASKER

i thought that is just an interface without any implementation?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtcy

ASKER

I need to implement my own.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtcy

ASKER

I have my class extends DefaultMutableTreeNode and above I have it import java.lang.*; it says cant resolve the class~
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtcy

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?
Avatar of jtcy

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.DefaultMutableTreeNode

the package that you are suppose to import is

import javax.swing.tree.DefaultMutableTreeNode;

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> which package does DefaultMutablewatever class from?

see my original comment:
javax.swing.tree.DefaultMutableTreeNode
Avatar of jtcy

ASKER

objects, which class should ur treeNode extend?
Avatar of jtcy

ASKER

does arrayList works like vector where we don need to keep its element offset? and its size gets incremented automatically?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtcy

ASKER

how do i do square root in java?
Math.sqrt(<double>);
Avatar of jtcy

ASKER

if a variable is int, says int distance, can i do :
distance = Math.sqrt((double) distance); ??
yes you can

distance = (int)Math.sqrt((double) distance);
Avatar of jtcy

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

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtcy

ASKER

objects, could u write getParents for me please?~ i am stuck of it.
no longer interested in our input?
OK.
getParent could be a TreeNode.

public TreeNode getParent(TreeNode node)
{
    return  node.getParent();
}
Avatar of jtcy

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.