Ayush Practical No 7
Ayush Practical No 7
Ayush Practical No 7
Roll No :- 76
X. ------------ ?
Code :-
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class JTreeEx1 {
JTree tree;
JFrame F;
JTreeEx1() {
F=new JFrame();
F.setLayout(new GridLayout());
tree=new JTree(top);
JScrollPane jsp=new JScrollPane(tree);
F.add(jsp,BorderLayout.CENTER);
F.setSize(500,550);
F.setVisible(true);
}
public static void main(String args[]) {
JTreeEx1 jte=new JTreeEx1();
}
}
Output :-
2. write a Program Code To Generate The Following Output.
Code :-
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
class MetroCity {
JTree tree;
JFrame F;
MetroCity() {
F=new JFrame();
F.setLayout(new GridLayout());
tree=new JTree(top);
F.setSize(500,550);
JScrollPane jsp=new JScrollPane(tree);
F.add(jsp,BorderLayout.CENTER);
F.setVisible(true);
}
public static void main(String args[]) {
MetroCity MC1=new MetroCity();
}
}
Output :-
XII. Exercise.
Write a JTree Program To Show Root Directory And It’s subFolders Of Your
System.
Code :-
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
JTreeEx() {
setLayout(new GridLayout());
setVisible(true);
setSize(450,400);
A.add(B);
A.add(C);
B.add(B1);
B.add(B2);
B.add(B3);
B.add(B4);
C.add(C1);
C.add(C2);
JTree T1=new JTree(A);
add(T1);
}
public static void main(String args[]) {
new JTreeEx();
}
}
Output :-