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

📄 filesystem.java

📁 一本有关Java图形界面设计的一本书,英文的,附带有源码,
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.List; // we don't want java.awt.List


/**
 * FileSystem is a window displays a given directory subtree.
 */
public class FileSystem extends JFrame {

    /**
     * Make a FileSystem window.
     * @param root Root of directory subtree to display in the new window
     */
    public FileSystem(File root) {
        super("File System: " + root);
                
        // call System.exit() when user closes the window
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        // traverse the filesystem recursively, starting at root
        traverse(root);
    }
    
    // Traverse the filesystem subtree rooted at f.
    // @effects Currently prints the names of files found to standard output.
    // Change this to have the appropriate effects on your window.
    private void traverse(File f) {        
        System.out.println(f.getPath());
        
        if (f.isDirectory()) {
            String[] children = f.list();
            for (int i = 0; i < children.length; ++i) {
                traverse(new File(f, children[i]));
            }
        }
    }
    
    
    /**
     * Main method.  Makes and displays a FileSystem window.
     * @param args Command-line arguments: args[0] should be the
     * pathname to display as the root.  If args[0] is omitted, 
     * uses the current directory instead.
     */
    public static void main(String[] args) {
        // root must be final so that it can be accessed from
        // the inner Runnable class below 
        final File root = 
            (args.length > 0) ? new File(args[0]) : new File(".");
            
        SwingUtilities.invokeLater(new Runnable() {
            public void run () {
                // Make and display the FileSystem window.
                new FileSystem(root).show();
            }
        });
    }    
    
    
}

⌨️ 快捷键说明

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