[go: up one dir, main page]

0% found this document useful (0 votes)
2 views3 pages

AJPm 7

The document contains three Java classes that create graphical user interface (GUI) applications using JTree components. Each class represents a different hierarchical structure: the first class has a generic tree structure, the second class represents geographical locations in India, and the third class simulates a file directory structure. All classes extend JFrame and utilize JScrollPane for displaying the trees with specified dimensions.

Uploaded by

pranavdhumal61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

AJPm 7

The document contains three Java classes that create graphical user interface (GUI) applications using JTree components. Each class represents a different hierarchical structure: the first class has a generic tree structure, the second class represents geographical locations in India, and the third class simulates a file directory structure. All classes extend JFrame and utilize JScrollPane for displaying the trees with specified dimensions.

Uploaded by

pranavdhumal61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

O/P-

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);

JTree t1= new JTree(i);


int h= ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS; O/P-
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
JScrollPane js= new JScrollPane(t1,v,h);
add(js);
js.setBounds(20,20,250,300);
setLayout(null);
setVisible(true);
setSize(500,600);
}
public static void main(String[] args) {
new jtree2();
}
}

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();
}
}

You might also like