Professional Documents
Culture Documents
Ajp7. Minu
Ajp7. Minu
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class TreeExample {
JFrame f;
TreeExample(){
f=new JFrame();
DefaultMutableTreeNode top=new DefaultMutableTreeNode("India");
DefaultMutableTreeNode a=new DefaultMutableTreeNode("Maharashtra");
a.add(a1);
a.add(a2);
a.add(a3);
a.add(a4);
JTree jt=new JTree(top);
f.add(jt);
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String[] args) {
new TreeExample();
}}
OUTPUT:
2.Develop a program to demonstrate th use of tree component in swing
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class TreeExample {
JFrame f;
TreeExample(){
f=new JFrame();
DefaultMutableTreeNode top=new DefaultMutableTreeNode("India");
DefaultMutableTreeNode a=new DefaultMutableTreeNode("Maharashtra");
a.add(a1);
a.add(a2);
a.add(a3);
a.add(a4);
JTree jt=new JTree(top);
f.add(jt);
f.setSize(200,200);
f.setVisible(true);
}
public static void main(String[] args) {
new TreeExample();
}}
OUTPUT: