import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class Tree {
Tree(){
JFrame f=new JFrame();
DefaultMutableTreeNode s=new DefaultMutableTreeNode("India");
DefaultMutableTreeNode s2=new DefaultMutableTreeNode("Maharashtra");
DefaultMutableTreeNode s3=new DefaultMutableTreeNode("Gujrath");
s.add(s2);
s.add(s3);
DefaultMutableTreeNode s4=new DefaultMutableTreeNode("Mumbai");
DefaultMutableTreeNode s5=new DefaultMutableTreeNode("Pune");
DefaultMutableTreeNode s6=new DefaultMutableTreeNode("Nashik");
DefaultMutableTreeNode s7=new DefaultMutableTreeNode("Nagpur");
s2.add(s4);
s2.add(s5);
s2.add(s6);
s2.add(s7);
JTree j=new JTree(s);
f.add(j);
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String[] args) {
new Tree();
}}
OP:
import javax.swing.tree.DefaultMutableTreeNode;
public class Tree {
Tree(){
JFrame f=new JFrame();
DefaultMutableTreeNode s=new DefaultMutableTreeNode("India");
DefaultMutableTreeNode s2=new DefaultMutableTreeNode("Maharashtra");
DefaultMutableTreeNode s3=new DefaultMutableTreeNode("Gujrath");
s.add(s2);
s.add(s3);
DefaultMutableTreeNode s4=new DefaultMutableTreeNode("Mumbai");
DefaultMutableTreeNode s5=new DefaultMutableTreeNode("Pune");
DefaultMutableTreeNode s6=new DefaultMutableTreeNode("Nashik");
DefaultMutableTreeNode s7=new DefaultMutableTreeNode("Nagpur");
s2.add(s4);
s2.add(s5);
s2.add(s6);
s2.add(s7);
JTree j=new JTree(s);
f.add(j);
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String[] args) {
new Tree();
}}
OP:
..
ReplyDelete