thanks
11 个解决方案
#1
最简单的例子
public void maketree()
{
String query = "select dwmc from ";
root = new DefaultMutableTreeNode("世界");
country = new DefaultMutableTreeNode("中国");
city = new DefaultMutableTreeNode("济南");
root.add(country);
country.add(city);
country = new DefaultMutableTreeNode("美国");
root.add(country);
city = new DefaultMutableTreeNode("旧金山");
country.add(city);
treemodel = new DefaultTreeModel(root);
tree = new JTree(treemodel);
}
public void maketree()
{
String query = "select dwmc from ";
root = new DefaultMutableTreeNode("世界");
country = new DefaultMutableTreeNode("中国");
city = new DefaultMutableTreeNode("济南");
root.add(country);
country.add(city);
country = new DefaultMutableTreeNode("美国");
root.add(country);
city = new DefaultMutableTreeNode("旧金山");
country.add(city);
treemodel = new DefaultTreeModel(root);
tree = new JTree(treemodel);
}
#2
package com.maxmell.util;
public class Tree implements java.io.Serializable{
/**
* 保存所有的节点。
*/
private java.util.Hashtable m_nodes=new java.util.Hashtable();
/**
* 添加节点为指定节点的子节点。
* @param id 节点标志
* @param text 节点标题
* @param value 节点值
* @param order 节点次序
* @param parent_id 上层节点对象
* @return 添加的节点对象
*/
public Node add(String id,String text,int value,int order,Node parent){
if(parent!=null&&m_nodes.get(parent.getId())==null)return null;
Node n=new Node(id,text,value,order,parent);
this.m_nodes.put(id,n);
return n;
}
/**
* 通过节点标志取得节点对象。
* @param id 节点标志
* @return 节点对象
*/
public Node findNode(String id){
return (Node)m_nodes.get(id);
}
/**
* 删除节点及其所有子节点。
* @param id 节点标志
*/
public void delete(String id){
m_nodes.remove(id);
}
/**
* 删除节点及其所有子节点。
* @param n 节点对象
*/
public void delete(Node n){
java.util.Enumeration nodes=this.getSubNodes(n);
while(nodes.hasMoreElements())
delete((Node)nodes.nextElement());
m_nodes.remove(n.getId());
}
/**
* 返回节点总数。
* @return 节点总数
*/
public int count(){
return m_nodes.size();
}
/**
* 取得所有根节点。
* @return 根节点集合
*/
public java.util.Enumeration getTopNodes(){
return getSubNodes(null);
}
/**
* 取得某个节点的所有子节点。
* @param parent 节点对象,为null则取得根节点集合
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent){
java.util.Vector subNodes=new java.util.Vector();
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n.getParent()==parent)
subNodes.add(n);
}
return subNodes.elements();
}
/**
* 取得某个节点的所有子节点,并排序。
* @param parent 节点对象,为null则取得根节点集合
* @param isDesc 排列顺序,<code>true</code>为降序,<code>false</code>为升序。
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
java.util.Vector v=new java.util.Vector();
java.util.Enumeration e=getSubNodes(parent);
int index=0;
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
int i=0;
for(i=0;i<v.size();i++){
int cmp=compare((Node)v.get(i),n);
if( (cmp<=0 && isDesc) || (cmp>=0 && !isDesc))break;
}
v.insertElementAt(n,i);
}
return v.elements();
}
/**
* 取得所有叶子节点。
* @return 叶子节点集合
*/
public java.util.Enumeration getTailNodes(){
java.util.Hashtable nodes=(java.util.Hashtable)m_nodes.clone();
java.util.Enumeration e=nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n!=null)n=n.getParent();
if(n!=null)nodes.remove(n.getId());
}
return nodes.elements();
}
/**
* 取得节点的值。
* @param n 节点对象
* @return 节点值
*/
public int getValue(Node n){
return n.getValue();
}
/**
* 取得从根节点到该节点的值的总和。
* @param n 节点对象
* @return 节点值总和
*/
public int getValues(Node n){
int v=0;
Node p=n;
while(p!=null){
v+=p.getValue();
p=p.getParent();
}
return v;
}
/**
* 取得所有节点的最大值。
* @return 节点值
*/
public int getMaxValue(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValue((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得值总和最大的分支
* @return 节点值总和
*/
public int getMaxValues(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValues((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得该节的深度,即层数
* @param n 节点对象
* @return 层数
*/
public int getDeep(Node n){
int deep=0;
Node p=n;
while(p!=null){
deep++;
p=p.getParent();
}
return deep;
}
/**
* 取得所有分支中最大的层数
* @return 层数
*/
public int getMaxDeep(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getDeep((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得上层节点,返回null则为根节点
* @param n 节点对象
* @return 上层节点对象
*/
public Node getParentNode(Node n){
return n.getParent();
}
/**
* 判断是否为叶子节点
* @param n 节点对象
* @return 指定节点是叶子节点返回<code>true</code>,否则返回<code>false</code>。
*/
public boolean isTailNode(Node n){
return !this.getSubNodes(n).hasMoreElements();
}
/**
* 取得所有节点的集合
* @return 所有节点的集合。
*/
public java.util.Enumeration getNodes(){
return m_nodes.elements();
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param s 节点标志
* @return 所有节点的集合。
*/
public String getNodeFullText(String s){
return getNodeFullText(findNode(s));
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param n 节点
* @return 所有节点的集合。
*/
public String getNodeFullText(Node n){
if(n!=null){
if(n.getParent()!=null)
return getNodeFullText(n.getParent())+" - "+n.getText();
return n.getText();
}
return "";
}
/**
* 取得以指定节点为根节点的子树。
* @param top 指定的节点
* @return 子树
*/
public Tree getSubTree(Node top){
Tree tree=new Tree();
tree.add(top.getId(),top.getText(),top.getValue());
addSubNodes(tree,top.getId());
return tree;
}
//添加指定节点及其所有后续节点到指定的树。
private void addSubNodes(Tree tree,String parent){
if(findNode(parent)==null)return;
java.util.Enumeration e=this.getSubNodes(findNode(parent));
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
tree.add(n.getId(),n.getText(),n.getValue(),parent);
addSubNodes(tree,n.getId());
}
}
private int compare(Node n1,Node n2){
if(n1.getOrder()==n2.getOrder())return 0;
if(n1.getOrder()>n2.getOrder())return 1;
return -1;
}
}
public class Tree implements java.io.Serializable{
/**
* 保存所有的节点。
*/
private java.util.Hashtable m_nodes=new java.util.Hashtable();
/**
* 添加节点为指定节点的子节点。
* @param id 节点标志
* @param text 节点标题
* @param value 节点值
* @param order 节点次序
* @param parent_id 上层节点对象
* @return 添加的节点对象
*/
public Node add(String id,String text,int value,int order,Node parent){
if(parent!=null&&m_nodes.get(parent.getId())==null)return null;
Node n=new Node(id,text,value,order,parent);
this.m_nodes.put(id,n);
return n;
}
/**
* 通过节点标志取得节点对象。
* @param id 节点标志
* @return 节点对象
*/
public Node findNode(String id){
return (Node)m_nodes.get(id);
}
/**
* 删除节点及其所有子节点。
* @param id 节点标志
*/
public void delete(String id){
m_nodes.remove(id);
}
/**
* 删除节点及其所有子节点。
* @param n 节点对象
*/
public void delete(Node n){
java.util.Enumeration nodes=this.getSubNodes(n);
while(nodes.hasMoreElements())
delete((Node)nodes.nextElement());
m_nodes.remove(n.getId());
}
/**
* 返回节点总数。
* @return 节点总数
*/
public int count(){
return m_nodes.size();
}
/**
* 取得所有根节点。
* @return 根节点集合
*/
public java.util.Enumeration getTopNodes(){
return getSubNodes(null);
}
/**
* 取得某个节点的所有子节点。
* @param parent 节点对象,为null则取得根节点集合
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent){
java.util.Vector subNodes=new java.util.Vector();
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n.getParent()==parent)
subNodes.add(n);
}
return subNodes.elements();
}
/**
* 取得某个节点的所有子节点,并排序。
* @param parent 节点对象,为null则取得根节点集合
* @param isDesc 排列顺序,<code>true</code>为降序,<code>false</code>为升序。
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
java.util.Vector v=new java.util.Vector();
java.util.Enumeration e=getSubNodes(parent);
int index=0;
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
int i=0;
for(i=0;i<v.size();i++){
int cmp=compare((Node)v.get(i),n);
if( (cmp<=0 && isDesc) || (cmp>=0 && !isDesc))break;
}
v.insertElementAt(n,i);
}
return v.elements();
}
/**
* 取得所有叶子节点。
* @return 叶子节点集合
*/
public java.util.Enumeration getTailNodes(){
java.util.Hashtable nodes=(java.util.Hashtable)m_nodes.clone();
java.util.Enumeration e=nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n!=null)n=n.getParent();
if(n!=null)nodes.remove(n.getId());
}
return nodes.elements();
}
/**
* 取得节点的值。
* @param n 节点对象
* @return 节点值
*/
public int getValue(Node n){
return n.getValue();
}
/**
* 取得从根节点到该节点的值的总和。
* @param n 节点对象
* @return 节点值总和
*/
public int getValues(Node n){
int v=0;
Node p=n;
while(p!=null){
v+=p.getValue();
p=p.getParent();
}
return v;
}
/**
* 取得所有节点的最大值。
* @return 节点值
*/
public int getMaxValue(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValue((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得值总和最大的分支
* @return 节点值总和
*/
public int getMaxValues(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValues((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得该节的深度,即层数
* @param n 节点对象
* @return 层数
*/
public int getDeep(Node n){
int deep=0;
Node p=n;
while(p!=null){
deep++;
p=p.getParent();
}
return deep;
}
/**
* 取得所有分支中最大的层数
* @return 层数
*/
public int getMaxDeep(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getDeep((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得上层节点,返回null则为根节点
* @param n 节点对象
* @return 上层节点对象
*/
public Node getParentNode(Node n){
return n.getParent();
}
/**
* 判断是否为叶子节点
* @param n 节点对象
* @return 指定节点是叶子节点返回<code>true</code>,否则返回<code>false</code>。
*/
public boolean isTailNode(Node n){
return !this.getSubNodes(n).hasMoreElements();
}
/**
* 取得所有节点的集合
* @return 所有节点的集合。
*/
public java.util.Enumeration getNodes(){
return m_nodes.elements();
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param s 节点标志
* @return 所有节点的集合。
*/
public String getNodeFullText(String s){
return getNodeFullText(findNode(s));
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param n 节点
* @return 所有节点的集合。
*/
public String getNodeFullText(Node n){
if(n!=null){
if(n.getParent()!=null)
return getNodeFullText(n.getParent())+" - "+n.getText();
return n.getText();
}
return "";
}
/**
* 取得以指定节点为根节点的子树。
* @param top 指定的节点
* @return 子树
*/
public Tree getSubTree(Node top){
Tree tree=new Tree();
tree.add(top.getId(),top.getText(),top.getValue());
addSubNodes(tree,top.getId());
return tree;
}
//添加指定节点及其所有后续节点到指定的树。
private void addSubNodes(Tree tree,String parent){
if(findNode(parent)==null)return;
java.util.Enumeration e=this.getSubNodes(findNode(parent));
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
tree.add(n.getId(),n.getText(),n.getValue(),parent);
addSubNodes(tree,n.getId());
}
}
private int compare(Node n1,Node n2){
if(n1.getOrder()==n2.getOrder())return 0;
if(n1.getOrder()>n2.getOrder())return 1;
return -1;
}
}
#3
测试代码:
static public void print(Tree t,Node n,int deep){
java.util.Enumeration nodes=t.getSubNodes(n,false);
for(int i=0;i<deep;i++)System.out.print("\t");
if(n!=null)System.out.println(n.getId()+"-"+n.getText()+","+n.getValue());
while(nodes.hasMoreElements())
print(t,(Node)nodes.nextElement(),deep+1);
}
static public void main(String[] argv){
Tree t=new Tree();
Node root=t.add("root","Root",10);
t.add("Sub1","Sub item 1",5,root);
t.add("root1","root 1",10);
Node sub2=t.add("sub2","Sub Item 2",5,root);
Node sub3=t.add("sub3","Sub Item 3",5,root);
Node sub4=t.add("sub4","Sub Item 4",5,root);
Node sub5=t.add("sub5","Sub Item 5",5,root);
Node sub6=t.add("sub6","Sub Item 6",5,root);
t.add("sub2sub1","Sub Item 2/1",3,sub2);
t.add("sub2sub2","Sub Item 2/2",3,sub2);
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
t.add("sub2sub4","Sub Item 2/4",3,sub2);
t.add("sub2sub5","Sub Item 2/5",3,sub2);
t.add("sub2sub6","Sub Item 2/6",3,sub2);
t.add("sub2sub7","Sub Item 2/7",3,sub2);
t.add("sub3sub1","Sub Item 3/1",3,sub3);
t.add("sub3sub2","Sub Item 3/2",3,sub3);
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
t.add("sub3sub4","Sub Item 3/4",3,sub3);
t.add("sub3sub5","Sub Item 3/5",3,sub3);
t.add("sub4sub1","Sub item 1/4",5,sub4);
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
t.add("sub2sub3sub1","Sub Item 1/3/2",7,sub23);
t.add("sub2sub3sub2","Sub Item 2/3/2",7,sub23);
t.add("sub2sub3sub3","Sub Item 3/3/2",7,sub23);
t.add("sub2sub3sub4","Sub Item 4/3/2",7,sub23);
//t.add("ff","fffffff",10,"dwdw");
t.delete("sub5");
//t.delete("sub2");
print(t,null,0);
System.out.println("------------------------------------------------");
System.out.println("Tree Node count is:"+t.count());
System.out.println("Tree deep is:"+t.getMaxDeep());
System.out.println("Tree max values is:"+t.getMaxValues());
System.out.println("-----------Tail nodes-------------------------------------");
java.util.Enumeration e=t.getTailNodes();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
System.out.print(" "+n.getId());
}
System.out.println();
System.out.println("-----------Sub tree sub3-------------------------------------");
Tree nt=t.getSubTree(sub3);
print(nt,null,0);
System.out.println("-----------Sub tree sub2-------------------------------------");
Tree nt2=t.getSubTree(sub2);
print(nt2,null,0);
System.out.println("-----------all nodes-------------------------------------");
java.util.Enumeration e2=t.getNodes();
while(e2.hasMoreElements()){
Node n=(Node)e2.nextElement();
if(t.isTailNode(n)){
System.out.println("Node "+n.getId()+" is tail node.");
}else
System.out.println("Node "+n.getId()+" is not tail node.");
}
}
static public void print(Tree t,Node n,int deep){
java.util.Enumeration nodes=t.getSubNodes(n,false);
for(int i=0;i<deep;i++)System.out.print("\t");
if(n!=null)System.out.println(n.getId()+"-"+n.getText()+","+n.getValue());
while(nodes.hasMoreElements())
print(t,(Node)nodes.nextElement(),deep+1);
}
static public void main(String[] argv){
Tree t=new Tree();
Node root=t.add("root","Root",10);
t.add("Sub1","Sub item 1",5,root);
t.add("root1","root 1",10);
Node sub2=t.add("sub2","Sub Item 2",5,root);
Node sub3=t.add("sub3","Sub Item 3",5,root);
Node sub4=t.add("sub4","Sub Item 4",5,root);
Node sub5=t.add("sub5","Sub Item 5",5,root);
Node sub6=t.add("sub6","Sub Item 6",5,root);
t.add("sub2sub1","Sub Item 2/1",3,sub2);
t.add("sub2sub2","Sub Item 2/2",3,sub2);
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
t.add("sub2sub4","Sub Item 2/4",3,sub2);
t.add("sub2sub5","Sub Item 2/5",3,sub2);
t.add("sub2sub6","Sub Item 2/6",3,sub2);
t.add("sub2sub7","Sub Item 2/7",3,sub2);
t.add("sub3sub1","Sub Item 3/1",3,sub3);
t.add("sub3sub2","Sub Item 3/2",3,sub3);
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
t.add("sub3sub4","Sub Item 3/4",3,sub3);
t.add("sub3sub5","Sub Item 3/5",3,sub3);
t.add("sub4sub1","Sub item 1/4",5,sub4);
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
t.add("sub2sub3sub1","Sub Item 1/3/2",7,sub23);
t.add("sub2sub3sub2","Sub Item 2/3/2",7,sub23);
t.add("sub2sub3sub3","Sub Item 3/3/2",7,sub23);
t.add("sub2sub3sub4","Sub Item 4/3/2",7,sub23);
//t.add("ff","fffffff",10,"dwdw");
t.delete("sub5");
//t.delete("sub2");
print(t,null,0);
System.out.println("------------------------------------------------");
System.out.println("Tree Node count is:"+t.count());
System.out.println("Tree deep is:"+t.getMaxDeep());
System.out.println("Tree max values is:"+t.getMaxValues());
System.out.println("-----------Tail nodes-------------------------------------");
java.util.Enumeration e=t.getTailNodes();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
System.out.print(" "+n.getId());
}
System.out.println();
System.out.println("-----------Sub tree sub3-------------------------------------");
Tree nt=t.getSubTree(sub3);
print(nt,null,0);
System.out.println("-----------Sub tree sub2-------------------------------------");
Tree nt2=t.getSubTree(sub2);
print(nt2,null,0);
System.out.println("-----------all nodes-------------------------------------");
java.util.Enumeration e2=t.getNodes();
while(e2.hasMoreElements()){
Node n=(Node)e2.nextElement();
if(t.isTailNode(n)){
System.out.println("Node "+n.getId()+" is tail node.");
}else
System.out.println("Node "+n.getId()+" is not tail node.");
}
}
#4
刚好要做个树型目录,真谢谢大家!
#5
我运行过,怎么错误???
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:29: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node findNode(String id){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: cannot resolve symbol
symbol : class Node
location: class star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: delete(java.lang.String) is already defined in star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:73: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:90: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:126: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValue(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:135: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValues(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:180: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getDeep(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:219: cannot resolve symbol
symbol : class Node
location: class star.Tree
public boolean isTailNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: cannot resolve symbol
symbol : class Node
location: class star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: getNodeFullText(java.lang.String) is already defined in star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:259: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Tree getSubTree(Node top){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\?烂鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:284: cannot resolve symbol
symbol : class Node
location: class star.Tree
static public void print(Tree t,Node n,int deep){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:30: cannot resolve symbol
symbol : class Node
location: class star.Tree
return (Node)m_nodes.get(id);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:48: cannot resolve symbol
symbol : class Node
location: class star.Tree
delete((Node)nodes.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:98: cannot resolve symbol
symbol : class Node
location: class star.Tree
int cmp=compare((Node)v.get(i),n);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:114: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:29: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node findNode(String id){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: cannot resolve symbol
symbol : class Node
location: class star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: delete(java.lang.String) is already defined in star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:73: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:90: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:126: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValue(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:135: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValues(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:180: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getDeep(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:219: cannot resolve symbol
symbol : class Node
location: class star.Tree
public boolean isTailNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: cannot resolve symbol
symbol : class Node
location: class star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: getNodeFullText(java.lang.String) is already defined in star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:259: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Tree getSubTree(Node top){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\?烂鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:284: cannot resolve symbol
symbol : class Node
location: class star.Tree
static public void print(Tree t,Node n,int deep){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:30: cannot resolve symbol
symbol : class Node
location: class star.Tree
return (Node)m_nodes.get(id);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:48: cannot resolve symbol
symbol : class Node
location: class star.Tree
delete((Node)nodes.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:98: cannot resolve symbol
symbol : class Node
location: class star.Tree
int cmp=compare((Node)v.get(i),n);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:114: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
#6
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:114: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:137: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:139: inconvertible types
found : java.lang.String
required: int
v+=p.getValue();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:154: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValue((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:169: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValues((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:182: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:199: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getDeep((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:289: cannot resolve symbol
symbol : class Node
location: class star.Tree
print(t,(Node)nodes.nextElement(),deep+1);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:296: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
t.add("root1","root 1",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:297: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub2=t.add("sub2","Sub Item 2",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:298: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3=t.add("sub3","Sub Item 3",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:299: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub4=t.add("sub4","Sub Item 4",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:300: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub5=t.add("sub5","Sub Item 5",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:301: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub6=t.add("sub6","Sub Item 6",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:304: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:312: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:317: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
^
C:\Documents and Settings\Administrator\桌?鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:318: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
55 errors
Process completed.
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:137: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:139: inconvertible types
found : java.lang.String
required: int
v+=p.getValue();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:154: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValue((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:169: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValues((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:182: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:199: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getDeep((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:289: cannot resolve symbol
symbol : class Node
location: class star.Tree
print(t,(Node)nodes.nextElement(),deep+1);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:296: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
t.add("root1","root 1",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:297: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub2=t.add("sub2","Sub Item 2",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:298: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3=t.add("sub3","Sub Item 3",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:299: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub4=t.add("sub4","Sub Item 4",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:300: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub5=t.add("sub5","Sub Item 5",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:301: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub6=t.add("sub6","Sub Item 6",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:304: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:312: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:317: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
^
C:\Documents and Settings\Administrator\桌?鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:318: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
55 errors
Process completed.
#7
你要纯JAVA的吗?JAVA有一个类就是TREE类。不是很复杂的。
#8
发到你邮箱了。
#9
TREE类不是真正的TREE吧
#10
能给我发一份吗?alpstong00@yahoo.com.cn
谢谢
谢谢
#11
也能给我发一份吗?xin_yu_yang@126.com
谢谢!!!!!
谢谢!!!!!
#1
最简单的例子
public void maketree()
{
String query = "select dwmc from ";
root = new DefaultMutableTreeNode("世界");
country = new DefaultMutableTreeNode("中国");
city = new DefaultMutableTreeNode("济南");
root.add(country);
country.add(city);
country = new DefaultMutableTreeNode("美国");
root.add(country);
city = new DefaultMutableTreeNode("旧金山");
country.add(city);
treemodel = new DefaultTreeModel(root);
tree = new JTree(treemodel);
}
public void maketree()
{
String query = "select dwmc from ";
root = new DefaultMutableTreeNode("世界");
country = new DefaultMutableTreeNode("中国");
city = new DefaultMutableTreeNode("济南");
root.add(country);
country.add(city);
country = new DefaultMutableTreeNode("美国");
root.add(country);
city = new DefaultMutableTreeNode("旧金山");
country.add(city);
treemodel = new DefaultTreeModel(root);
tree = new JTree(treemodel);
}
#2
package com.maxmell.util;
public class Tree implements java.io.Serializable{
/**
* 保存所有的节点。
*/
private java.util.Hashtable m_nodes=new java.util.Hashtable();
/**
* 添加节点为指定节点的子节点。
* @param id 节点标志
* @param text 节点标题
* @param value 节点值
* @param order 节点次序
* @param parent_id 上层节点对象
* @return 添加的节点对象
*/
public Node add(String id,String text,int value,int order,Node parent){
if(parent!=null&&m_nodes.get(parent.getId())==null)return null;
Node n=new Node(id,text,value,order,parent);
this.m_nodes.put(id,n);
return n;
}
/**
* 通过节点标志取得节点对象。
* @param id 节点标志
* @return 节点对象
*/
public Node findNode(String id){
return (Node)m_nodes.get(id);
}
/**
* 删除节点及其所有子节点。
* @param id 节点标志
*/
public void delete(String id){
m_nodes.remove(id);
}
/**
* 删除节点及其所有子节点。
* @param n 节点对象
*/
public void delete(Node n){
java.util.Enumeration nodes=this.getSubNodes(n);
while(nodes.hasMoreElements())
delete((Node)nodes.nextElement());
m_nodes.remove(n.getId());
}
/**
* 返回节点总数。
* @return 节点总数
*/
public int count(){
return m_nodes.size();
}
/**
* 取得所有根节点。
* @return 根节点集合
*/
public java.util.Enumeration getTopNodes(){
return getSubNodes(null);
}
/**
* 取得某个节点的所有子节点。
* @param parent 节点对象,为null则取得根节点集合
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent){
java.util.Vector subNodes=new java.util.Vector();
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n.getParent()==parent)
subNodes.add(n);
}
return subNodes.elements();
}
/**
* 取得某个节点的所有子节点,并排序。
* @param parent 节点对象,为null则取得根节点集合
* @param isDesc 排列顺序,<code>true</code>为降序,<code>false</code>为升序。
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
java.util.Vector v=new java.util.Vector();
java.util.Enumeration e=getSubNodes(parent);
int index=0;
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
int i=0;
for(i=0;i<v.size();i++){
int cmp=compare((Node)v.get(i),n);
if( (cmp<=0 && isDesc) || (cmp>=0 && !isDesc))break;
}
v.insertElementAt(n,i);
}
return v.elements();
}
/**
* 取得所有叶子节点。
* @return 叶子节点集合
*/
public java.util.Enumeration getTailNodes(){
java.util.Hashtable nodes=(java.util.Hashtable)m_nodes.clone();
java.util.Enumeration e=nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n!=null)n=n.getParent();
if(n!=null)nodes.remove(n.getId());
}
return nodes.elements();
}
/**
* 取得节点的值。
* @param n 节点对象
* @return 节点值
*/
public int getValue(Node n){
return n.getValue();
}
/**
* 取得从根节点到该节点的值的总和。
* @param n 节点对象
* @return 节点值总和
*/
public int getValues(Node n){
int v=0;
Node p=n;
while(p!=null){
v+=p.getValue();
p=p.getParent();
}
return v;
}
/**
* 取得所有节点的最大值。
* @return 节点值
*/
public int getMaxValue(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValue((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得值总和最大的分支
* @return 节点值总和
*/
public int getMaxValues(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValues((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得该节的深度,即层数
* @param n 节点对象
* @return 层数
*/
public int getDeep(Node n){
int deep=0;
Node p=n;
while(p!=null){
deep++;
p=p.getParent();
}
return deep;
}
/**
* 取得所有分支中最大的层数
* @return 层数
*/
public int getMaxDeep(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getDeep((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得上层节点,返回null则为根节点
* @param n 节点对象
* @return 上层节点对象
*/
public Node getParentNode(Node n){
return n.getParent();
}
/**
* 判断是否为叶子节点
* @param n 节点对象
* @return 指定节点是叶子节点返回<code>true</code>,否则返回<code>false</code>。
*/
public boolean isTailNode(Node n){
return !this.getSubNodes(n).hasMoreElements();
}
/**
* 取得所有节点的集合
* @return 所有节点的集合。
*/
public java.util.Enumeration getNodes(){
return m_nodes.elements();
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param s 节点标志
* @return 所有节点的集合。
*/
public String getNodeFullText(String s){
return getNodeFullText(findNode(s));
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param n 节点
* @return 所有节点的集合。
*/
public String getNodeFullText(Node n){
if(n!=null){
if(n.getParent()!=null)
return getNodeFullText(n.getParent())+" - "+n.getText();
return n.getText();
}
return "";
}
/**
* 取得以指定节点为根节点的子树。
* @param top 指定的节点
* @return 子树
*/
public Tree getSubTree(Node top){
Tree tree=new Tree();
tree.add(top.getId(),top.getText(),top.getValue());
addSubNodes(tree,top.getId());
return tree;
}
//添加指定节点及其所有后续节点到指定的树。
private void addSubNodes(Tree tree,String parent){
if(findNode(parent)==null)return;
java.util.Enumeration e=this.getSubNodes(findNode(parent));
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
tree.add(n.getId(),n.getText(),n.getValue(),parent);
addSubNodes(tree,n.getId());
}
}
private int compare(Node n1,Node n2){
if(n1.getOrder()==n2.getOrder())return 0;
if(n1.getOrder()>n2.getOrder())return 1;
return -1;
}
}
public class Tree implements java.io.Serializable{
/**
* 保存所有的节点。
*/
private java.util.Hashtable m_nodes=new java.util.Hashtable();
/**
* 添加节点为指定节点的子节点。
* @param id 节点标志
* @param text 节点标题
* @param value 节点值
* @param order 节点次序
* @param parent_id 上层节点对象
* @return 添加的节点对象
*/
public Node add(String id,String text,int value,int order,Node parent){
if(parent!=null&&m_nodes.get(parent.getId())==null)return null;
Node n=new Node(id,text,value,order,parent);
this.m_nodes.put(id,n);
return n;
}
/**
* 通过节点标志取得节点对象。
* @param id 节点标志
* @return 节点对象
*/
public Node findNode(String id){
return (Node)m_nodes.get(id);
}
/**
* 删除节点及其所有子节点。
* @param id 节点标志
*/
public void delete(String id){
m_nodes.remove(id);
}
/**
* 删除节点及其所有子节点。
* @param n 节点对象
*/
public void delete(Node n){
java.util.Enumeration nodes=this.getSubNodes(n);
while(nodes.hasMoreElements())
delete((Node)nodes.nextElement());
m_nodes.remove(n.getId());
}
/**
* 返回节点总数。
* @return 节点总数
*/
public int count(){
return m_nodes.size();
}
/**
* 取得所有根节点。
* @return 根节点集合
*/
public java.util.Enumeration getTopNodes(){
return getSubNodes(null);
}
/**
* 取得某个节点的所有子节点。
* @param parent 节点对象,为null则取得根节点集合
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent){
java.util.Vector subNodes=new java.util.Vector();
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n.getParent()==parent)
subNodes.add(n);
}
return subNodes.elements();
}
/**
* 取得某个节点的所有子节点,并排序。
* @param parent 节点对象,为null则取得根节点集合
* @param isDesc 排列顺序,<code>true</code>为降序,<code>false</code>为升序。
* @return 子节点集合
*/
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
java.util.Vector v=new java.util.Vector();
java.util.Enumeration e=getSubNodes(parent);
int index=0;
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
int i=0;
for(i=0;i<v.size();i++){
int cmp=compare((Node)v.get(i),n);
if( (cmp<=0 && isDesc) || (cmp>=0 && !isDesc))break;
}
v.insertElementAt(n,i);
}
return v.elements();
}
/**
* 取得所有叶子节点。
* @return 叶子节点集合
*/
public java.util.Enumeration getTailNodes(){
java.util.Hashtable nodes=(java.util.Hashtable)m_nodes.clone();
java.util.Enumeration e=nodes.elements();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
if(n!=null)n=n.getParent();
if(n!=null)nodes.remove(n.getId());
}
return nodes.elements();
}
/**
* 取得节点的值。
* @param n 节点对象
* @return 节点值
*/
public int getValue(Node n){
return n.getValue();
}
/**
* 取得从根节点到该节点的值的总和。
* @param n 节点对象
* @return 节点值总和
*/
public int getValues(Node n){
int v=0;
Node p=n;
while(p!=null){
v+=p.getValue();
p=p.getParent();
}
return v;
}
/**
* 取得所有节点的最大值。
* @return 节点值
*/
public int getMaxValue(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValue((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得值总和最大的分支
* @return 节点值总和
*/
public int getMaxValues(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getValues((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得该节的深度,即层数
* @param n 节点对象
* @return 层数
*/
public int getDeep(Node n){
int deep=0;
Node p=n;
while(p!=null){
deep++;
p=p.getParent();
}
return deep;
}
/**
* 取得所有分支中最大的层数
* @return 层数
*/
public int getMaxDeep(){
int v=0;
int v1=0;
java.util.Enumeration e=m_nodes.elements();
while(e.hasMoreElements()){
v1=getDeep((Node)e.nextElement());
if(v<v1)v=v1;
}
return v;
}
/**
* 取得上层节点,返回null则为根节点
* @param n 节点对象
* @return 上层节点对象
*/
public Node getParentNode(Node n){
return n.getParent();
}
/**
* 判断是否为叶子节点
* @param n 节点对象
* @return 指定节点是叶子节点返回<code>true</code>,否则返回<code>false</code>。
*/
public boolean isTailNode(Node n){
return !this.getSubNodes(n).hasMoreElements();
}
/**
* 取得所有节点的集合
* @return 所有节点的集合。
*/
public java.util.Enumeration getNodes(){
return m_nodes.elements();
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param s 节点标志
* @return 所有节点的集合。
*/
public String getNodeFullText(String s){
return getNodeFullText(findNode(s));
}
/**
* 取得指定节点全名,全名指从根节点到该节点用'-'串起来的名称
* @param n 节点
* @return 所有节点的集合。
*/
public String getNodeFullText(Node n){
if(n!=null){
if(n.getParent()!=null)
return getNodeFullText(n.getParent())+" - "+n.getText();
return n.getText();
}
return "";
}
/**
* 取得以指定节点为根节点的子树。
* @param top 指定的节点
* @return 子树
*/
public Tree getSubTree(Node top){
Tree tree=new Tree();
tree.add(top.getId(),top.getText(),top.getValue());
addSubNodes(tree,top.getId());
return tree;
}
//添加指定节点及其所有后续节点到指定的树。
private void addSubNodes(Tree tree,String parent){
if(findNode(parent)==null)return;
java.util.Enumeration e=this.getSubNodes(findNode(parent));
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
tree.add(n.getId(),n.getText(),n.getValue(),parent);
addSubNodes(tree,n.getId());
}
}
private int compare(Node n1,Node n2){
if(n1.getOrder()==n2.getOrder())return 0;
if(n1.getOrder()>n2.getOrder())return 1;
return -1;
}
}
#3
测试代码:
static public void print(Tree t,Node n,int deep){
java.util.Enumeration nodes=t.getSubNodes(n,false);
for(int i=0;i<deep;i++)System.out.print("\t");
if(n!=null)System.out.println(n.getId()+"-"+n.getText()+","+n.getValue());
while(nodes.hasMoreElements())
print(t,(Node)nodes.nextElement(),deep+1);
}
static public void main(String[] argv){
Tree t=new Tree();
Node root=t.add("root","Root",10);
t.add("Sub1","Sub item 1",5,root);
t.add("root1","root 1",10);
Node sub2=t.add("sub2","Sub Item 2",5,root);
Node sub3=t.add("sub3","Sub Item 3",5,root);
Node sub4=t.add("sub4","Sub Item 4",5,root);
Node sub5=t.add("sub5","Sub Item 5",5,root);
Node sub6=t.add("sub6","Sub Item 6",5,root);
t.add("sub2sub1","Sub Item 2/1",3,sub2);
t.add("sub2sub2","Sub Item 2/2",3,sub2);
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
t.add("sub2sub4","Sub Item 2/4",3,sub2);
t.add("sub2sub5","Sub Item 2/5",3,sub2);
t.add("sub2sub6","Sub Item 2/6",3,sub2);
t.add("sub2sub7","Sub Item 2/7",3,sub2);
t.add("sub3sub1","Sub Item 3/1",3,sub3);
t.add("sub3sub2","Sub Item 3/2",3,sub3);
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
t.add("sub3sub4","Sub Item 3/4",3,sub3);
t.add("sub3sub5","Sub Item 3/5",3,sub3);
t.add("sub4sub1","Sub item 1/4",5,sub4);
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
t.add("sub2sub3sub1","Sub Item 1/3/2",7,sub23);
t.add("sub2sub3sub2","Sub Item 2/3/2",7,sub23);
t.add("sub2sub3sub3","Sub Item 3/3/2",7,sub23);
t.add("sub2sub3sub4","Sub Item 4/3/2",7,sub23);
//t.add("ff","fffffff",10,"dwdw");
t.delete("sub5");
//t.delete("sub2");
print(t,null,0);
System.out.println("------------------------------------------------");
System.out.println("Tree Node count is:"+t.count());
System.out.println("Tree deep is:"+t.getMaxDeep());
System.out.println("Tree max values is:"+t.getMaxValues());
System.out.println("-----------Tail nodes-------------------------------------");
java.util.Enumeration e=t.getTailNodes();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
System.out.print(" "+n.getId());
}
System.out.println();
System.out.println("-----------Sub tree sub3-------------------------------------");
Tree nt=t.getSubTree(sub3);
print(nt,null,0);
System.out.println("-----------Sub tree sub2-------------------------------------");
Tree nt2=t.getSubTree(sub2);
print(nt2,null,0);
System.out.println("-----------all nodes-------------------------------------");
java.util.Enumeration e2=t.getNodes();
while(e2.hasMoreElements()){
Node n=(Node)e2.nextElement();
if(t.isTailNode(n)){
System.out.println("Node "+n.getId()+" is tail node.");
}else
System.out.println("Node "+n.getId()+" is not tail node.");
}
}
static public void print(Tree t,Node n,int deep){
java.util.Enumeration nodes=t.getSubNodes(n,false);
for(int i=0;i<deep;i++)System.out.print("\t");
if(n!=null)System.out.println(n.getId()+"-"+n.getText()+","+n.getValue());
while(nodes.hasMoreElements())
print(t,(Node)nodes.nextElement(),deep+1);
}
static public void main(String[] argv){
Tree t=new Tree();
Node root=t.add("root","Root",10);
t.add("Sub1","Sub item 1",5,root);
t.add("root1","root 1",10);
Node sub2=t.add("sub2","Sub Item 2",5,root);
Node sub3=t.add("sub3","Sub Item 3",5,root);
Node sub4=t.add("sub4","Sub Item 4",5,root);
Node sub5=t.add("sub5","Sub Item 5",5,root);
Node sub6=t.add("sub6","Sub Item 6",5,root);
t.add("sub2sub1","Sub Item 2/1",3,sub2);
t.add("sub2sub2","Sub Item 2/2",3,sub2);
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
t.add("sub2sub4","Sub Item 2/4",3,sub2);
t.add("sub2sub5","Sub Item 2/5",3,sub2);
t.add("sub2sub6","Sub Item 2/6",3,sub2);
t.add("sub2sub7","Sub Item 2/7",3,sub2);
t.add("sub3sub1","Sub Item 3/1",3,sub3);
t.add("sub3sub2","Sub Item 3/2",3,sub3);
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
t.add("sub3sub4","Sub Item 3/4",3,sub3);
t.add("sub3sub5","Sub Item 3/5",3,sub3);
t.add("sub4sub1","Sub item 1/4",5,sub4);
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
t.add("sub2sub3sub1","Sub Item 1/3/2",7,sub23);
t.add("sub2sub3sub2","Sub Item 2/3/2",7,sub23);
t.add("sub2sub3sub3","Sub Item 3/3/2",7,sub23);
t.add("sub2sub3sub4","Sub Item 4/3/2",7,sub23);
//t.add("ff","fffffff",10,"dwdw");
t.delete("sub5");
//t.delete("sub2");
print(t,null,0);
System.out.println("------------------------------------------------");
System.out.println("Tree Node count is:"+t.count());
System.out.println("Tree deep is:"+t.getMaxDeep());
System.out.println("Tree max values is:"+t.getMaxValues());
System.out.println("-----------Tail nodes-------------------------------------");
java.util.Enumeration e=t.getTailNodes();
while(e.hasMoreElements()){
Node n=(Node)e.nextElement();
System.out.print(" "+n.getId());
}
System.out.println();
System.out.println("-----------Sub tree sub3-------------------------------------");
Tree nt=t.getSubTree(sub3);
print(nt,null,0);
System.out.println("-----------Sub tree sub2-------------------------------------");
Tree nt2=t.getSubTree(sub2);
print(nt2,null,0);
System.out.println("-----------all nodes-------------------------------------");
java.util.Enumeration e2=t.getNodes();
while(e2.hasMoreElements()){
Node n=(Node)e2.nextElement();
if(t.isTailNode(n)){
System.out.println("Node "+n.getId()+" is tail node.");
}else
System.out.println("Node "+n.getId()+" is not tail node.");
}
}
#4
刚好要做个树型目录,真谢谢大家!
#5
我运行过,怎么错误???
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:29: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node findNode(String id){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: cannot resolve symbol
symbol : class Node
location: class star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: delete(java.lang.String) is already defined in star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:73: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:90: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:126: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValue(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:135: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValues(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:180: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getDeep(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:219: cannot resolve symbol
symbol : class Node
location: class star.Tree
public boolean isTailNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: cannot resolve symbol
symbol : class Node
location: class star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: getNodeFullText(java.lang.String) is already defined in star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:259: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Tree getSubTree(Node top){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\?烂鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:284: cannot resolve symbol
symbol : class Node
location: class star.Tree
static public void print(Tree t,Node n,int deep){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:30: cannot resolve symbol
symbol : class Node
location: class star.Tree
return (Node)m_nodes.get(id);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:48: cannot resolve symbol
symbol : class Node
location: class star.Tree
delete((Node)nodes.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:98: cannot resolve symbol
symbol : class Node
location: class star.Tree
int cmp=compare((Node)v.get(i),n);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:114: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:17: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node add(String id,String text,int value,int order,Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:29: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node findNode(String id){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: cannot resolve symbol
symbol : class Node
location: class star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:45: delete(java.lang.String) is already defined in star.Tree
public void delete(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:73: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:90: cannot resolve symbol
symbol : class Node
location: class star.Tree
public java.util.Enumeration getSubNodes(Node parent,boolean isDesc){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:126: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValue(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:135: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getValues(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:180: cannot resolve symbol
symbol : class Node
location: class star.Tree
public int getDeep(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:210: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Node getParentNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:219: cannot resolve symbol
symbol : class Node
location: class star.Tree
public boolean isTailNode(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: cannot resolve symbol
symbol : class Node
location: class star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:245: getNodeFullText(java.lang.String) is already defined in star.Tree
public String getNodeFullText(Node n){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:259: cannot resolve symbol
symbol : class Node
location: class star.Tree
public Tree getSubTree(Node top){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\?烂鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:277: cannot resolve symbol
symbol : class Node
location: class star.Tree
private int compare(Node n1,Node n2){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:284: cannot resolve symbol
symbol : class Node
location: class star.Tree
static public void print(Tree t,Node n,int deep){
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:19: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=new Node(id,text,value,order,parent);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:30: cannot resolve symbol
symbol : class Node
location: class star.Tree
return (Node)m_nodes.get(id);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:48: cannot resolve symbol
symbol : class Node
location: class star.Tree
delete((Node)nodes.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:77: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:95: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:98: cannot resolve symbol
symbol : class Node
location: class star.Tree
int cmp=compare((Node)v.get(i),n);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:114: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
#6
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:114: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:137: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:139: inconvertible types
found : java.lang.String
required: int
v+=p.getValue();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:154: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValue((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:169: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValues((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:182: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:199: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getDeep((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:289: cannot resolve symbol
symbol : class Node
location: class star.Tree
print(t,(Node)nodes.nextElement(),deep+1);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:296: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
t.add("root1","root 1",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:297: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub2=t.add("sub2","Sub Item 2",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:298: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3=t.add("sub3","Sub Item 3",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:299: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub4=t.add("sub4","Sub Item 4",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:300: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub5=t.add("sub5","Sub Item 5",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:301: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub6=t.add("sub6","Sub Item 6",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:304: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:312: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:317: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
^
C:\Documents and Settings\Administrator\桌?鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:318: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
55 errors
Process completed.
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:137: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:139: inconvertible types
found : java.lang.String
required: int
v+=p.getValue();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:154: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValue((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:169: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getValues((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:182: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node p=n;
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:199: cannot resolve symbol
symbol : class Node
location: class star.Tree
v1=getDeep((Node)e.nextElement());
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:271: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:289: cannot resolve symbol
symbol : class Node
location: class star.Tree
print(t,(Node)nodes.nextElement(),deep+1);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:294: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
Node root=t.add("root","Root",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:296: add(java.lang.String,java.lang.String,int,int,Node) in star.Tree cannot be applied to (java.lang.String,java.lang.String,int)
t.add("root1","root 1",10);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:297: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub2=t.add("sub2","Sub Item 2",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:298: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3=t.add("sub3","Sub Item 3",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:299: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub4=t.add("sub4","Sub Item 4",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:300: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub5=t.add("sub5","Sub Item 5",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:301: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub6=t.add("sub6","Sub Item 6",5,root);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:304: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub23=t.add("sub2sub3","Sub Item 2/3",3,sub2);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:312: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub33=t.add("sub3sub3","Sub Item 3/3",3,sub3);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:317: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub331 = t.add("sub3sub3sub1","Sub item 1/3/3",3,sub33);
^
C:\Documents and Settings\Administrator\桌?鎈java涉及的东西\JAVA_Tree\Tree1\Tree.java:318: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node sub3311 = t.add("sub3sub3sub1sub1","Sub item 1/1/3/3",3,sub331);
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:334: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
^
C:\Documents and Settings\Administrator\桌面\java涉及的东西\JAVA_Tree\Tree1\Tree.java:347: cannot resolve symbol
symbol : class Node
location: class star.Tree
Node n=(Node)e2.nextElement();
55 errors
Process completed.
#7
你要纯JAVA的吗?JAVA有一个类就是TREE类。不是很复杂的。
#8
发到你邮箱了。
#9
TREE类不是真正的TREE吧
#10
能给我发一份吗?alpstong00@yahoo.com.cn
谢谢
谢谢
#11
也能给我发一份吗?xin_yu_yang@126.com
谢谢!!!!!
谢谢!!!!!