Results 1 to 18 of 18

Thread: Help me now!

  1. #1
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default 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!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quite a thread title, "Help me now!", or should I say "demand"?

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default 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?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    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!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default 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,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by mandyj View Post
    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! ) .
    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.

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

    instead of expanding the thread and pushing me away! thanks a lot!
    We did not "push you away". We told you that we were not going to do your work for you.

  8. #8
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    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!

  9. #9
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default new nodes

    So... were you able to add the new nodes?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  10. #10
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    nope...I got some 13 errors while trying to call the style by different names. I am going through the tutorials as of now!

  11. #11
    Manofest's Avatar
    Manofest is offline Member
    Join Date
    Dec 2008
    Posts
    10
    Rep Power
    0

    Default

    Edit - sorry posted stuff then realised i wasnt helping much
    Last edited by Manofest; 12-30-2008 at 12:09 AM.

  12. #12
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    OK, so you changed the node names, but did you:
    • update the add methods?
    • indicate the type (DefaultMutableTreeNode) for each renamed tree node?

    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]);
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  13. #13
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    @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,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  14. #14
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    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

  15. #15
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Errors...

    Treetest.java:44: cannot find symbol
    symbol : variable S1
    location: class Tree1
    S1=new DefaultMutableTreeNode ("Sound");
    ^
    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:
    Java Code:
    [B][COLOR="Blue"]DefaultMutableTreeNode[/COLOR][/B] S1=new DefaultMutableTreeNode ("Sound");
    Gotta run.... will come back later.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  16. #16
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default More nastygrams...

    Treetest.java:45: cannot find symbol
    symbol : variable S1
    location: class Tree1
    root2.add(S1);
    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.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  17. #17
    mandyj is offline Member
    Join Date
    Dec 2008
    Posts
    11
    Rep Power
    0

    Default

    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

  18. #18
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Need to see new code

    Since the code has changed, it would probably be better if you posted your new code.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •