WorldCupTree.java
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
class WorldCupTree extends JFrame
{
DefaultMutableTreeNode wc,wc99,wc99p,wc99w,wc03,wc03p,wc03w,wc07,wc07p,wc07w,wc11,wc11p,wc11w;
DefaultTreeModel model;
JTree tree;
WorldCupTree()
{
super ("WORLD CUP STATISTICS");
setSize(500,500);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
Container c=getContentPane();
wc=new DefaultMutableTreeNode("World Cup Statistics");
wc99=new DefaultMutableTreeNode("World Cup 1999");
wc99p=new DefaultMutableTreeNode("Played in England ");
wc99w=new DefaultMutableTreeNode("Won by Australia");
wc99.add(wc99p);
wc99.add(wc99w);
wc03=new DefaultMutableTreeNode("World Cup 2003");
wc03p=new DefaultMutableTreeNode("Played in South Africa");
wc03w=new DefaultMutableTreeNode("Won by Australia");
wc03.add(wc03p);
wc03.add(wc03w);
wc07=new DefaultMutableTreeNode("World Cup 2007");
wc07p=new DefaultMutableTreeNode("Played in West Indies");
wc07w=new DefaultMutableTreeNode("Won by Australia");
wc07.add(wc07p);
wc07.add(wc07w);
wc11=new DefaultMutableTreeNode("World Cup 2011");
wc11p=new DefaultMutableTreeNode("Played in Asia");
wc11w=new DefaultMutableTreeNode(" Won by India");
wc11.add(wc11p);
wc11.add(wc11w);
wc.add(wc99);
wc.add(wc03);
wc.add(wc07);
wc.add(wc11);
model=new DefaultTreeModel (wc);
tree=new JTree(model);
tree.setBounds(100,100,200,500);
c.add(tree);
setVisible(true);
}
public static void main(String [] args)
{
WorldCupTree app=new WorldCupTree();
}
}
------------------------------------------------Output will look like ------------------------------------------------
0 comments:
Post a Comment