⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monkeytreebean.java

📁 java 实现的动态树 java 实现的动态树
💻 JAVA
字号:
/* NeXt:recursion tutorial
 * next@keyboardmonkey.com
 */
package com.km.struts.tutorial.recursion;

import java.io.*;
import java.util.*;

/** This is a class you write yourself in the <NeXt:recursion tutorial>
 */
public class MonkeyTreeBean extends org.apache.struts.action.ActionForm {
  
  /* empty constructor for the bean */  
  public MonkeyTreeBean() {  
    this.beanName = "MonkeyTreeBean"; 
     
    /* load local directory */ 
    File localDir = new File("D:\\dev"); 
     
    /* create initial tree, and pass it to our directory loader */ 
    this.monkeyTree = new TreeNode(localDir.getName(),0); 
    this.addDirsAsNodes(localDir.listFiles(), this.monkeyTree); 
  }
  
  
  /* adds a new TreeNode object to a tree for every
    directory in the file list */  
  private void addDirsAsNodes(File[] f, TreeNode t) { 
    /* loop through child directories */ 
    for (int i = 0; i < f.length; i++) { 
      if (f[i].isDirectory()) { 
         
        /* create new node to add */ 
        TreeNode newNode = new TreeNode(f[i].getName(), depthCount); 
        t.addChild(newNode); 
         
        /* check our depth, then recurse to add child folders */ 
        if (depthCount < depthLimit) { 
          depthCount++; 
          addDirsAsNodes(f[i].listFiles(), newNode); 
          depthCount--; 
        } 
      } 
    } 
  } 
   
  /* getter method for the "beanName" property */ 
  public String getBeanName() { 
    return this.beanName; 
  }
  
  /* returns the reference to the monkey tree */
  public TreeNode getMonkeyTree() {
    return this.monkeyTree;
  }
 

  /* usual member variables */ 
  private int depthLimit = 3; 
  private int depthCount = 1; 
   
  private String beanName; 
  private TreeNode monkeyTree;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -