0% found this document useful (0 votes)
9 views

Practical No 7

Advance java practice no 7

Uploaded by

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

Practical No 7

Advance java practice no 7

Uploaded by

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

Practical no 7

Program code:-

import javax.swing.*;

import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.*;

public class TreeDemo1 {

private JTree tree;

private JFrame f;

TreeDemo1() {

f = new JFrame("Tree Demo");

f.setLayout(new BorderLayout());

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Tree");

DefaultMutableTreeNode a = new DefaultMutableTreeNode("a");

DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("b");

DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("c");

DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("d");

DefaultMutableTreeNode a4 = new DefaultMutableTreeNode("e");

top.add(a);

top.add(a1);

top.add(a2);

top.add(a3);

top.add(a4);

tree = new JTree(top);

JScrollPane j = new JScrollPane(tree);

f.add(j, BorderLayout.CENTER);

f.setSize(500, 400);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);

public static void main(String[] args) {

TreeDemo1 td =new TreeDemo1();

Output

2]

import javax.swing.*;

import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.*;

public class TreeDemo {

private JTree tree;

private JFrame f;

TreeDemo() {

f = new JFrame("Tree Demo");

f.setLayout(new BorderLayout());

DefaultMutableTreeNode top = new DefaultMutableTreeNode("India");


DefaultMutableTreeNode a = new DefaultMutableTreeNode("Maharashtra");

DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("Mumbai");

DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("pune");

DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("Nashik");

DefaultMutableTreeNode a4 = new DefaultMutableTreeNode("Nagpur");

top.add(a);

a.add(a1);

a.add(a2);

a.add(a3);

a.add(a4);

DefaultMutableTreeNode b = new DefaultMutableTreeNode("Gujrath");

top.add(b);

tree = new JTree(top);

JScrollPane j = new JScrollPane(tree);

f.add(j, BorderLayout.CENTER);

f.setSize(500, 400);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

public static void main(String[] args) {

TreeDemo td = new TreeDemo();

Output
XIII. Exercise

import javax.swing.*;

import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.*;

public class TreeDemo2 {

private JTree tree;

private JFrame f;

TreeDemo2() {

f = new JFrame("Tree Demo");

f.setLayout(new BorderLayout());

DefaultMutableTreeNode top = new DefaultMutableTreeNode("This Pc");

DefaultMutableTreeNode a = new DefaultMutableTreeNode("Local Disk(C:)");

DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("SWINDOWS.~BT");

DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("SWinREAgent");

DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("2203101");

DefaultMutableTreeNode a4 = new DefaultMutableTreeNode("MSOCache");

DefaultMutableTreeNode b = new DefaultMutableTreeNode("Local Disk(D:)");


DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("AJP");

DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("220308");

DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("220348");

top.add(a);

top.add(b);

a.add(a1);

a.add(a2);

a.add(a3);

a.add(a4);

b.add(b1);

b.add(b2);

b.add(b3);

tree = new JTree(top);

JScrollPane j = new JScrollPane(tree);

f.add(j, BorderLayout.CENTER);

f.setSize(500, 400);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setVisible(true);

public static void main(String[] args) {

TreeDemo2 td = new TreeDemo2();

Output:-

You might also like