0% found this document useful (0 votes)
6 views1 page

PracticalNo7 1

The document outlines a practical programming task to create a JTree in Java. It includes the code for a JFrame displaying a hierarchical tree structure representing Indian states and cities. The program utilizes Swing components to visualize the tree structure with nodes for India, Maharashtra, and various cities.

Uploaded by

Ashish Mavani
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)
6 views1 page

PracticalNo7 1

The document outlines a practical programming task to create a JTree in Java. It includes the code for a JFrame displaying a hierarchical tree structure representing Indian states and cities. The program utilizes Swing components to visualize the tree structure with nodes for India, Maharashtra, and various cities.

Uploaded by

Ashish Mavani
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/ 1

Practical No.

: 07

Practical Name: Write a program to create a JTree.

Roll No.: 47

Student Name: Mavani Ashish Shantilal

Program:
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;

class practical7_1
{
public static void main(String args[])
{
JFrame f = new JFrame("Practical 7");
f.setVisible(true);
f.setSize(500,300);
f.setLayout(new FlowLayout());

DefaultMutableTreeNode n1 = new DefaultMutableTreeNode("India");


DefaultMutableTreeNode n2 = new DefaultMutableTreeNode("Maharashtra");
DefaultMutableTreeNode n3 = new DefaultMutableTreeNode("Gujarat");
n1.add(n2);
n1.add(n3);
DefaultMutableTreeNode n4 = new DefaultMutableTreeNode("Mumbai");
DefaultMutableTreeNode n5 = new DefaultMutableTreeNode("Pune");
DefaultMutableTreeNode n6 = new DefaultMutableTreeNode("Nashik");
DefaultMutableTreeNode n7 = new DefaultMutableTreeNode("Nagpur");
n2.add(n4);
n2.add(n5);
n2.add(n6);
n2.add(n7);

JTree t = new JTree(n1);


f.add(t);
}
}
Output:

You might also like