AJPm 7
AJPm 7
Practical 7
X.
1.
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
public class jtree extends JFrame {
jtree(){
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child1");
DefaultMutableTreeNode subchild = new DefaultMutableTreeNode("subchild");
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child2");
DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Child3");
root.add(child1);
child1.add(subchild);
root.add(child2);
root.add(child3);
JTree t1= new JTree(root);
int h= ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
JScrollPane js= new JScrollPane(t1,v,h);
add(js);
js.setBounds(100,100,250,300);
setLayout(null);
setVisible(true);
setSize(500,600);
}
public static void main(String[] args) {
new jtree();
}
}
2.
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class jtree2 extends JFrame {
jtree2(){
DefaultMutableTreeNode i = new DefaultMutableTreeNode("India");
DefaultMutableTreeNode m = new DefaultMutableTreeNode("Maharashtra");
DefaultMutableTreeNode mb = new DefaultMutableTreeNode("Mumbai");
DefaultMutableTreeNode p = new DefaultMutableTreeNode("Pune");
DefaultMutableTreeNode n = new DefaultMutableTreeNode("Nashik");
DefaultMutableTreeNode ng = new DefaultMutableTreeNode("Nagpur");
DefaultMutableTreeNode g = new DefaultMutableTreeNode("Gujrat");
i.add(m);
m.add(mb);
m.add(n);
m.add(ng);
i.add(g);
XIII.
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class jtree3 extends JFrame {
jtree3(){
DefaultMutableTreeNode root = new DefaultMutableTreeNode("C drive");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Program files");
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("PerfLogs");
DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Oracleexe");
DefaultMutableTreeNode child4 = new DefaultMutableTreeNode("Windows");
root.add(child1);
root.add(child2);
root.add(child3);
root.add(child4);
JTree t1= new JTree(root); O/P-
int h= ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
JScrollPane js= new JScrollPane(t1,v,h);
add(js);
js.setBounds(100,100,250,300);
setLayout(null);
setVisible(true);
setSize(500,600);
}
public static void main(String[] args) {
new jtree3();
}
}