import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/*<applet code="Jswing" width=400 height=400>
</applet>*/
public class Jswing extends JApplet
{
JTree tree;
JTextField jtf;
public void init()
{
Container contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
DefaultMutableTreeNode clg=new DefaultMutableTreeNode("SRNM");
DefaultMutableTreeNode slf=new DefaultMutableTreeNode("SELF");
clg.add(slf);
DefaultMutableTreeNode ug=new DefaultMutableTreeNode("UG");
slf.add(ug);
DefaultMutableTreeNode pg=new DefaultMutableTreeNode("PG");
slg.add(pg);
DefaultMutableTreeNode max=new DefaultMutableTreeNode("B.Sc Maths");
ug.add(max);
DefaultMutableTreeNode phy=new DefaultMutableTreeNode("B.Sc Physics");
ug.add(phy);
DefaultMutableTreeNode eng=new DefaultMutableTreeNode("B.A English");
ug.add(eng);
DefaultMutableTreeNode com=new DefaultMutableTreeNode("B.Com");
ug.add(com);
DefaultMutableTreeNode pcs=new DefaultMutableTreeNode("M.Sc CS");
pg.add(pcs);
DefaultMutableTreeNode pca=new DefaultMutableTreeNode("M.C.A");
pg.add(pca);
DefaultMutableTreeNode reg=new DefaultMutableTreeNode("Regular");
clg.add(reg);
DefaultMutableTreeNode ug1=new DefaultMutableTreeNode("UG");
reg.add(ug1);
DefaultMutableTreeNode cs=new DefaultMutableTreeNode("B.C.A");
reg.add(cs);
DefaultMutableTreeNode ca=new DefaultMutableTreeNode("B.Com CA");
reg.add(ca);
DefaultMutableTreeNode pg1=new DefaultMutableTreeNode("PG");
reg.add(pg1);
DefaultMutableTreeNode pch=new DefaultMutableTreeNode("M.Sc Chemistry");
pg1.add(pch);
DefaultMutableTreeNode pcom=new DefaultMutableTreeNode("M.Com");
pg1.add(pcom);
tree=new JTree(clg);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(tree,v,h);
contentPane.add(jsp,BorderLayout.CENTER);
jtf=new JTextField("",20);
contentPane.add(jtf,BorderLayout.SOUTH);
tree.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
doMouseClicked(me);
}
});
}
void doMouseClicked(MouseEvent me)
{
TreePath tp=tree.getPathForLocation(me.getX(),me.getY());
if(tp!=null)
jtf.setText(tp.toString());
else
jtf.setText("");
}
}
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
/*<applet code="Jswing" width=400 height=400>
</applet>*/
public class Jswing extends JApplet
{
JTree tree;
JTextField jtf;
public void init()
{
Container contentPane=getContentPane();
contentPane.setLayout(new BorderLayout());
DefaultMutableTreeNode clg=new DefaultMutableTreeNode("SRNM");
DefaultMutableTreeNode slf=new DefaultMutableTreeNode("SELF");
clg.add(slf);
DefaultMutableTreeNode ug=new DefaultMutableTreeNode("UG");
slf.add(ug);
DefaultMutableTreeNode pg=new DefaultMutableTreeNode("PG");
slg.add(pg);
DefaultMutableTreeNode max=new DefaultMutableTreeNode("B.Sc Maths");
ug.add(max);
DefaultMutableTreeNode phy=new DefaultMutableTreeNode("B.Sc Physics");
ug.add(phy);
DefaultMutableTreeNode eng=new DefaultMutableTreeNode("B.A English");
ug.add(eng);
DefaultMutableTreeNode com=new DefaultMutableTreeNode("B.Com");
ug.add(com);
DefaultMutableTreeNode pcs=new DefaultMutableTreeNode("M.Sc CS");
pg.add(pcs);
DefaultMutableTreeNode pca=new DefaultMutableTreeNode("M.C.A");
pg.add(pca);
DefaultMutableTreeNode reg=new DefaultMutableTreeNode("Regular");
clg.add(reg);
DefaultMutableTreeNode ug1=new DefaultMutableTreeNode("UG");
reg.add(ug1);
DefaultMutableTreeNode cs=new DefaultMutableTreeNode("B.C.A");
reg.add(cs);
DefaultMutableTreeNode ca=new DefaultMutableTreeNode("B.Com CA");
reg.add(ca);
DefaultMutableTreeNode pg1=new DefaultMutableTreeNode("PG");
reg.add(pg1);
DefaultMutableTreeNode pch=new DefaultMutableTreeNode("M.Sc Chemistry");
pg1.add(pch);
DefaultMutableTreeNode pcom=new DefaultMutableTreeNode("M.Com");
pg1.add(pcom);
tree=new JTree(clg);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp=new JScrollPane(tree,v,h);
contentPane.add(jsp,BorderLayout.CENTER);
jtf=new JTextField("",20);
contentPane.add(jtf,BorderLayout.SOUTH);
tree.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
doMouseClicked(me);
}
});
}
void doMouseClicked(MouseEvent me)
{
TreePath tp=tree.getPathForLocation(me.getX(),me.getY());
if(tp!=null)
jtf.setText(tp.toString());
else
jtf.setText("");
}
}
0 comments:
Post a Comment