This document contains the source code for a Java program that creates a tree of animal nodes. It defines nodes for various animals like birds, reptiles, and mammals and adds them to a tree structure displayed in a JFrame window. The summary asks how to insert new animal nodes like elephant and butterfly into the tree, and how to count the total number of animals currently in the tree.
This document contains the source code for a Java program that creates a tree of animal nodes. It defines nodes for various animals like birds, reptiles, and mammals and adds them to a tree structure displayed in a JFrame window. The summary asks how to insert new animal nodes like elephant and butterfly into the tree, and how to count the total number of animals currently in the tree.
This document contains the source code for a Java program that creates a tree of animal nodes. It defines nodes for various animals like birds, reptiles, and mammals and adds them to a tree structure displayed in a JFrame window. The summary asks how to insert new animal nodes like elephant and butterfly into the tree, and how to count the total number of animals currently in the tree.
package j avat r eebook00; import j avax.swi ng.*; import j avax.swi ng.t r ee.*; publ i c cl ass Test 5Ani mal Tr ee { publ i c st at i c voi d mai n(St r i ng[] ar gs) { J Fr ame f r ame = new J Fr ame(" Cr eat i ng a J Tr ee Ani mal ! "); Def aul t Mut abl eTr eeNode canar y = new Def aul t Mut abl eTr eeNode(" Canar y"); canar y.add(new Def aul t Mut abl eTr eeNode(" Tweet l e")); Def aul t Mut abl eTr eeNode bi r d = new Def aul t Mut abl eTr eeNode(" Bi r d"); bi r d.add(canar y); Def aul t Mut abl eTr eeNode l i zar d = new Def aul t Mut abl eTr eeNode(" Li zar d"); l i zar d.add(new Def aul t Mut abl eTr eeNode(" Sel amander ")); Def aul t Mut abl eTr eeNode r ept i l e = new Def aul t Mut abl eTr eeNode(" Rept i l e"); r ept i l e.add(l i zar d); r ept i l e.add(new Def aul t Mut abl eTr eeNode(" Snack")); r ept i l e.add(bi r d); Def aul t Mut abl eTr eeNode cow = new Def aul t Mut abl eTr eeNode(" Cow"); cow.add(new Def aul t Mut abl eTr eeNode(" Bessel ")); Def aul t Mut abl eTr eeNode bovi ne = new Def aul t Mut abl eTr eeNode(" Bovi ne"); bovi ne.add(cow); Def aul t Mut abl eTr eeNode mammal = new Def aul t Mut abl eTr eeNode(" Mammal "); mammal .add(new Def aul t Mut abl eTr eeNode(" Equi ne")); mammal .add(bovi ne); mammal .add(new Def aul t Mut abl eTr eeNode(" Cani ne")); Def aul t Mut abl eTr eeNode ani mal = new Def aul t Mut abl eTr eeNode(" Ani mal "); ani mal .add(r ept i l e); ani mal .add(mammal ); J Tr ee t r ee = new J Tr ee(ani mal ); f r ame.add(t r ee); f r ame.set Def aul t Cl oseOper at i on(J Fr ame.EXI T_ON_CLOSE); f r ame.set Undecor at ed(true); f r ame.get Root Pane().set Wi ndowDecor at i onSt yl e(J Root Pane.PLAI N_DI ALOG); f r ame.set Si ze(200, 400); f r ame.set Vi si bl e(true); } } -1- D:\100--ARISN-KULIAH\225--ASD2\004--JavaExample\JavaTreeBook00\src\javatreebook00\Test5AnimalTree.java Sunday, December 8, 2013 11:25 AM -2- Result of running the program From your task II, please try complete your program for this
- Write down your algoritmhs and computer program, how and where if we want to insert our new data such as (a) elephant, (b) butterfly.
- Find how many animal in your collection. Try to add these two nodes (lassle and rintintin) to tree