建立一个系统默认的简单树结构

/*最简单的JTree示例*/

class MyTree extends JFrame{

  public MyTree(String s){

    super(s);

    Container con = new getContentPane();

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("d:\\")

    DefaultMutableTreeNode t1 = new DefultMutableTreeNode("BFZL");

    DefaultMutableTreeNode t2 = new DefaultMutableTreeNode("JavaXX");

    DefaultMutableTreeNode t1_1 = new DefaultMutableTreeNode("SWJHTZ");

    DefaultMutableTreeNode t1_2 = new DefaultMutableTreeNode("WLYJ");

    DefaultMutableTreeNode t2_1 = new DefaultMutableTreeNode("SPJC");

    DefaultMutableTreeNode t2_2 = new DefaultMutableTreeNode("Java 3D");

    JTree jTree = new JTree(root);

    root.add(t1);root.add(t2);

    t1.add(t1_1);t1.add(t1_2);

    t2.add(t2_1);t2.add(t2_2);

    JScrollPane scrollPane = new JScrollPane(jTree);

    con.add(scrollPane);

    setSize(200,300);

    setLoction(500,100);

    setVisible(true);

    vildate();

    addWindowListener(new WindowAdapter(){

      public void windowClosing(WindowEvent e){

        System.exit(0);

      }

    });

  }

}

public class Example{

  public static void main(String[] args){

    new Mytree("利用TreeNode构造树");

  }

}

 

posted @ 2016-03-05 20:42  嘿壳  阅读(190)  评论(0编辑  收藏  举报