package learn;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class SimpleTree {
JFrame jf = new JFrame();
public void init()
{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("中国省份");
DefaultMutableTreeNode huBei = new DefaultMutableTreeNode("湖北省");
DefaultMutableTreeNode wuHan = new DefaultMutableTreeNode("武汉");
DefaultMutableTreeNode huangShi= new DefaultMutableTreeNode("黄石");
DefaultMutableTreeNode xiangYang = new DefaultMutableTreeNode("襄阳");
DefaultMutableTreeNode jingZhou = new DefaultMutableTreeNode("荆州");
DefaultMutableTreeNode yinChang = new DefaultMutableTreeNode("宜昌");
DefaultMutableTreeNode shiYan = new DefaultMutableTreeNode("十堰");
DefaultMutableTreeNode xiaoGan = new DefaultMutableTreeNode("孝感");
DefaultMutableTreeNode jinMen = new DefaultMutableTreeNode("荆门");
DefaultMutableTreeNode eZhou = new DefaultMutableTreeNode("鄂州");
DefaultMutableTreeNode huangGan = new DefaultMutableTreeNode("黄冈");
DefaultMutableTreeNode xianNing = new DefaultMutableTreeNode("咸宁");
DefaultMutableTreeNode suiZhou = new DefaultMutableTreeNode("随州");
DefaultMutableTreeNode enShi = new DefaultMutableTreeNode("恩施");
huBei.add(wuHan);
huBei.add(huangShi);
huBei.add(xiangYang);
huBei.add(jingZhou);
huBei.add(yinChang);
huBei.add(shiYan);
huBei.add(xiaoGan);
huBei.add(jinMen);
huBei.add(eZhou);
huBei.add(huangGan);
huBei.add(xianNing);
huBei.add(eZhou);
huBei.add(enShi);
root.add(huBei);
JTree tree = new JTree(root);
jf.add(tree);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
}
public static void main(String[] args) {
new SimpleTree().init();
}
}