import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
public class yanshi extends JFrame
{
protected JTree m_tree;
Container cp=getContentPane();
Font f=new Font( "TimesRoman ",Font.BOLD,24);
public yanshi()
{
Object[] nodes=new Object[5];
Dimension screen=getToolkit().getScreenSize();
cp.setLayout(new FlowLayout(FlowLayout.LEADING));
JLabel lb=new JLabel( "数据结构演示系统 ",JLabel.CENTER);
lb.setPreferredSize(new Dimension(screen.width-50,100));
lb.setFont(f);
lb.setForeground(Color.red);
lb.setBackground(Color.cyan);
cp.add(lb);
DefaultMutableTreeNode top=new DefaultMutableTreeNode(new OidNode(1, "线性表 "));
DefaultMutableTreeNode parent=top;
DefaultMutableTreeNode node=new DefaultMutableTreeNode(new OidNode(0, "顺序表 "));
parent.add(node);
parent=node;
node=new DefaultMutableTreeNode(new OidNode(1, "插入 "));
parent.add(node);
node=new DefaultMutableTreeNode(new OidNode(1, "删除 "));
parent.add(node);
m_tree=new JTree(top)
{
public String getToolTipText(MouseEvent e)
{
TreePath path=m_tree.getPathForLocation(e.getX(),e.getY());
if(path==null) return null;
Object[] nodes=path.getPath();
String oid= " ";
for(int k=0;k <nodes.length;k++)
{
DefaultMutableTreeNode treenode=(DefaultMutableTreeNode)nodes[k];
OidNode nd=(OidNode)treenode.getUserObject();
oid+= ". "+nd.getId();
}
return oid;
}
};
ToolTipManager.sharedInstance().registerComponent(m_tree);
m_tree.setShowsRootHandles(true);
m_tree.putClientProperty( "JTree.lineStyle ", "Angled ");
m_tree.setEditable(false);
m_tree.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e)
{
tvwTreeView_mouseClicked(e);
}
});
JScrollPane s=new JScrollPane(m_tree);
s.setPreferredSize(new Dimension(200,600));
getContentPane().add(s,BorderLayout.CENTER);
setSize(screen.width-50,screen.height-50);
setLocation(20,10);
setVisible(true);
cp.add(s);
JTextField tf=new JTextField();
tf.setPreferredSize(new Dimension(750,600));
cp.add(tf);
}
private void tvwTreeView_mouseClicked(MouseEvent e)
{
TreePath path=m_tree.getPathForLocation(e.getX(),e.getY());
if(path==null) return;
Object[] nodes=path.getPath();
String oid= " ";
for(int k=0;k <nodes.length;k++)
{
DefaultMutableTreeNode node=(DefaultMutableTreeNode)nodes[k];
OidNode nd=(OidNode)node.getUserObject();
oid+= ". "+nd.getName();
}
}
public static void main(String argv[])
{
yanshi ys=new yanshi();
ys.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}
class OidNode
{
private int m_id;
private String m_name;
public OidNode(int id,String name)