0% found this document useful (0 votes)
157 views4 pages

06 Hands-On Activity 1

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)
157 views4 pages

06 Hands-On Activity 1

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/ 4

Romanillos, Jenelyn November 20, 2022

BSIT 301

Part 1

OUTPUT

CODE:
import javax.swing.*;

import javax.swing.tree.DefaultMutableTreeNode;

public class Jtree {

JFrame f;

Jtree() {

f = new JFrame();

DefaultMutableTreeNode html = new DefaultMutableTreeNode("Html");

DefaultMutableTreeNode head = new DefaultMutableTreeNode("head");


DefaultMutableTreeNode body = new DefaultMutableTreeNode("Body");

html.add(head);

html.add(body);

DefaultMutableTreeNode meta = new DefaultMutableTreeNode("meta");

DefaultMutableTreeNode title = new DefaultMutableTreeNode("title");

head.add(meta);

head.add(title);

DefaultMutableTreeNode ul = new DefaultMutableTreeNode("ul");

DefaultMutableTreeNode h1 = new DefaultMutableTreeNode("h1");

DefaultMutableTreeNode h2 = new DefaultMutableTreeNode("h2");

body.add(ul);

body.add(h1);

body.add(h2);

DefaultMutableTreeNode li = new DefaultMutableTreeNode("li");

DefaultMutableTreeNode lI = new DefaultMutableTreeNode("lI");

ul.add(li);

ul.add(lI);

DefaultMutableTreeNode a = new DefaultMutableTreeNode("a");

h2.add(a);

JTree jt = new JTree(html);

f.add(jt);

f.setSize(300, 300);

f.setVisible(true);

public static void main(String[] args) {

new Jtree();

}
Part 2
root.add(n1);

root.add(n2);

n1.add(head1);

n1.add(head2);

n2.add(body1);

n2.add(body2);

n2.add(body3);

body1.add(ul1);

body1.add(ul2);

body3.add(h21);

System.out.println ("The root node is: "+head1.getRoot());

System.out.println ("The parent nodes are: "+n1.getParent()


+","+head1.getParent()+","+body1.getParent()+","+body2.getParent()
+","+ul1.getParent()+","+h21.getParent());

System.out.println ("The siblings are: "+Collections.list(root.children())


+""+Collections.list(n1.children())+""+Collections.list(n2.children())
+""+Collections.list(body1.children()));

System.out.println ("The one level subtrees: "+"\


n"+root+"-"+Collections.list(root.children()));System.out.println
(n1+"-"+Collections.list(n1.children()));System.out.println
(n2+"-"+Collections.list(n2.children()));

System.out.println
(body1+"-"+Collections.list(body1.children()));System.out.println
(body3+"-"+Collections.list(body3.children()));

System.out.println ("Nodes per level: "+ "\nLevel "+ root.getLevel()


+"-"+root.getRoot());System.out.println ("Level "+ n1.getLevel()
+"-"+n1+","+n2);
System.out.println ("Level "+ head1.getLevel()
+"-"+head1+","+head2+","+body1+","+body2+","+body3);System.out.println ("Level
"+ ul1.getLevel()+"-"+ul1+","+ul2+","+h21);

System.out.println ("Depth: "+root.getDepth());System.out.println ("The degree


of each one-level subtree: "+"\nSubtree
"+root+"-"+root.getChildCount());System.out.println ("Subtree
"+n1+"-"+n1.getChildCount());

System.out.println ("Subtree "+n2+"-"+n1.getChildCount());System.out.println


("Subtree "+body1+"-"+body1.getChildCount());System.out.println ("Subtree
"+body3+"-"+body3.getChildCount());

List bfe = Collections.list(root.breadthFirstEnumeration());System.out.println


("List of nodes based on breadth-first: "+bfe);

List pro = Collections.list(root.preorderEnumeration());System.out.println


("List of nodes based on preorder: "+pro);

List po = Collections.list(root.postorderEnumeration());System.out.println
("List of nodes based on postorder: "+po);

tree = new JTree(root);add(tree);

this.setTitle("JFrame Example");

this.setSize(300,300);this.setVisible(true);

public static void main(String args[]) {HtmlTree a = new HtmlTree();

You might also like