We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

TreeNode *urgent*

jtcy
jtcy asked
on
Medium Priority
322 Views
Last Modified: 2010-03-31
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~

Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
i thought that is just an interface without any implementation?
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I need to implement my own.
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I have my class extends DefaultMutableTreeNode and above I have it import java.lang.*; it says cant resolve the class~
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
>  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?

Author

Commented:
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;

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> which package does DefaultMutablewatever class from?

see my original comment:
javax.swing.tree.DefaultMutableTreeNode

Author

Commented:
objects, which class should ur treeNode extend?

Author

Commented:
does arrayList works like vector where we don need to keep its element offset? and its size gets incremented automatically?
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
how do i do square root in java?
Math.sqrt(<double>);

Author

Commented:
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);

Author

Commented:
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

Sr. Software engineer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
objects, could u write getParents for me please?~ i am stuck of it.
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
no longer interested in our input?
OK.
getParent could be a TreeNode.

public TreeNode getParent(TreeNode node)
{
    return  node.getParent();
}

Author

Commented:
will this work? an infinite recursion?
zzynxSr. Software engineer
CERTIFIED EXPERT

Commented:
jtcy, are you doing a "spring clean up" of all your open Q's?
Nevertheless, thanks for awarding our efforts.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.