/* Java Program To Display A simple tree with root node as ENGINEERING and the courses under it as sub nodes or leaves. The program makes use of Frames. The Normal way of defining a tree node is 'DefaultMutableTreeNode root_name =new DefaultMutableTreeNode (argument_name)'.*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class Tree1 extends JFrame
{
public static void main(String args[])
{
Tree1 frame = new Tree1(" A Tree");
frame.setSize(200,200);
frame.setVisible(true);
}
public Tree1(String title)
{
setTitle(title);
DefaultMutableTreeNode root=new DefaultMutableTreeNode ("Engineering");
DefaultMutableTreeNode style=new DefaultMutableTreeNode ("Information Technology");
root.add(style);
style=new DefaultMutableTreeNode("Electronics");
root.add(style);
style=new DefaultMutableTreeNode ("Computer Science");
root.add(style);
style=new DefaultMutableTreeNode ("Mechanical");
root.add(style);
style=new DefaultMutableTreeNode ("Electrical");
root.add(style);
style=new DefaultMutableTreeNode ("Sound");
root.add(style);
JTree jt=new JTree(root);
Container contentPane=getContentPane();
contentPane.add(new JScrollPane(jt));
}
}
Labels: Advanced Java, Frames, Swings
Subscribe to:
Post Comments (Atom)
THANKS. IT HELP ME AS MY GUIDE IN CREATING A TREES BY USING 10 ARRAY NAMES, AND HAVING SUBTREES.