Results 1 to 18 of 18
Thread: Help me now!
- 12-29-2008, 09:05 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
Help me now!
Dear friends,
I got this code this time... and don knw how to proceed further...plz modify my code as per the requirement i hv mentioned at the end of the code and I'll surely update my knowledge on this.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Tree1 extends JFrame
{
public static void main(String args[])
{
Tree1 frame = new Tree1(" A Tree");
frame.setSize(200,200);
frame.setVisible(true);
}
public Tree1(String title)
{
setTitle(title);
DefaultMutableTreeNode root=new DefaultMutableTreeNode ("Engineering");
DefaultMutableTreeNode style=new DefaultMutableTreeNode ("Information Technology");
root.add(style);
style=new DefaultMutableTreeNode("Electronics");
root.add(style);
style=new DefaultMutableTreeNode ("Computer Science");
root.add(style);
style=new DefaultMutableTreeNode ("Mechanical");
root.add(style);
style=new DefaultMutableTreeNode ("Electrical");
root.add(style);
style=new DefaultMutableTreeNode ("Sound");
root.add(style);
JTree jt=new JTree(root);
Container contentPane=getContentPane();
contentPane.add(new JScrollPane(jt));
}
}
But here i am able to show only one root node and then the leaf nodes....If I have to show some more root nodes and leaf nodes under them then how do I do that?? Please help!
-
Quite a thread title, "Help me now!", or should I say "demand"?
- 12-29-2008, 09:32 PM #3
You just don't learn, do you?
Mandyj: statements like "Help me now!" and "... modify my code per the requrements ..." is a very good way to NOT get any help. You can't demand help and nobody is going to do your code for you (as was explained to you in another post).
So what have you tried?
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-29-2008, 09:47 PM #4
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
I am again sorry if it sounds like a demand but if a beginner like me can't ask for help, what you guys are doing here ( R n D! ) . And by now, you sud know that i also don know the rules you follow in such forums where pple can't ask for code...which u guys might be able to give and cud be of great help to pple like me instead of expanding the thread and pushing me away! thanks a lot!
-
All you need to know about JTrees can be found here:
How to Use Trees
Give it a look, and study the sample code. It'll help you out, guaranteed!
Good luck.
- 12-29-2008, 10:01 PM #6
Please...
It's not about asking for help, it's how you ask for the help. Your tone is very demanding. There is a BIG difference between "Help me now!" vs "Need help with Tree frames". There is a BIG difference between "modify my code for me" vs "can you provide a pointer or hint". And nobody is pushing you away... just learn the way of the forum and you'll get lots of help.
As for the code, some observations:
- Don't call all your tree nodes the same (style). Give them different variable names.
For example:
Java Code:DefaultMutableTreeNode [B][COLOR="Blue"]infoTech[/COLOR][/B]=new DefaultMutableTreeNode ("Information Technology");- Now to add new nodes to the existing nodes, why don't you just create the new nodes and add them the new nodes.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-29-2008, 10:16 PM #7
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
No one said you couldn't ask for help, but demanding it (especially in the form of a handout), is not going to be taken kindly.
No, providing you code would not help you. You only think it would, since it would "solve" your current situation without any additional effort on your part. Well, what you do tomorrow, is, usually dependant on what you do today. But, since "giving" you code would mean you didn't do anything today, you'll be even worse off tomorrow.And by now, you sud know that i also don know the rules you follow in such forums where pple can't ask for code...which u guys might be able to give and cud be of great help to pple like me
We did not "push you away". We told you that we were not going to do your work for you.instead of expanding the thread and pushing me away! thanks a lot!
- 12-29-2008, 10:33 PM #8
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
Thanks a lot guys....I am slowly starting to know and understand and will keep in mind next time I post a thread or ask for help! And its not that I'll always rely on help and come here and ask for code. I knw my situation and that's why I had to ask in a hurry and unfortunately it had to end like this....sorry and thanks again! Keep up the great work!
- 12-29-2008, 10:36 PM #9
new nodes
So... were you able to add the new nodes?
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-29-2008, 10:50 PM #10
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
nope...I got some 13 errors while trying to call the style by different names. I am going through the tutorials as of now!
- 12-29-2008, 11:04 PM #11
Edit - sorry posted stuff then realised i wasnt helping much
Last edited by Manofest; 12-29-2008 at 11:09 PM.
- 12-29-2008, 11:12 PM #12
OK, so you changed the node names, but did you:
- update the add methods?
- indicate the type (DefaultMutableTreeNode) for each renamed tree node?
Luck,Java Code:[B][COLOR="Blue"]DefaultMutableTreeNode[/COLOR][/B] [B][COLOR="Blue"]infoTech[/COLOR][/B]=new DefaultMutableTreeNode ("Information Technology"); root.add([B][COLOR="blue"]infoTech[/COLOR][/B]);
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-29-2008, 11:17 PM #13
@Manofest: Good catch... usually posting complete code is not good for the OP... too much temptation to cut & paste & forget. No learning process.
@Mandyj: If you haven't figured out the errors, why don't you post them. Error messages (nastygrams :-) are also a source for learning.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-29-2008, 11:42 PM #14
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
Yes , I updated the add methods too. I got the errors like this->
Treetest.java:44: cannot find symbol
symbol : variable S1
location: class Tree1
S1=new DefaultMutableTreeNode ("Sound");
^
Treetest.java:45: cannot find symbol
symbol : variable S1
location: class Tree1
root2.add(S1);
^
Treetest.java:47: cannot find symbol
symbol : variable root1
location: class Tree1
JTree jt=new JTree(root1);
^
Treetest.java:48: jt is already defined in Tree1(java.lang.String)
JTree jt=new JTree(root2);
^
23 errors
- 12-29-2008, 11:54 PM #15
Errors...
The above error is because you didn't specify what type the S1 variable was. I'm sure if you put "DefaultMutableTreeNode" in front of the S1 variable delaration the error will go away:Treetest.java:44: cannot find symbol
symbol : variable S1
location: class Tree1
S1=new DefaultMutableTreeNode ("Sound");
^
Gotta run.... will come back later.Java Code:[B][COLOR="Blue"]DefaultMutableTreeNode[/COLOR][/B] S1=new DefaultMutableTreeNode ("Sound");
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-30-2008, 02:42 AM #16
More nastygrams...
The above error will go away if you fix the error I described in my previous post. ...and while I'm on this error, where did "root2" come from? The latest I knew was that there was only "root". I don't think you need a "root2", but then I'll confess that I'm not a jTable expert. If you want the existing nodes to have new nodes, just try adding new nodes to the existing nodes.Treetest.java:45: cannot find symbol
symbol : variable S1
location: class Tree1
root2.add(S1);
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-30-2008, 01:45 PM #17
Member
- Join Date
- Dec 2008
- Posts
- 11
- Rep Power
- 0
Ya..i gave 'root2' since i wanted 'root2' as another parent node with another set of child nodes like this->
-root1
| |-child1
| |-child2
| |-child3
|
-root2
|-child1
|-child2
|-child3
- 12-30-2008, 02:06 PM #18


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks