vssivl
克斯
发贴: 20
积分: 0
|
于 2004-11-05 18:03
package gui;
import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*;
public class FileTreeTest { public static void main(String[] args) { try { if (args.length != 1) { System.out.println("Please supply one initial directory"); System.exit(0); } JFrame f = new JFrame("File Tree Test"); final FileTree ft = new FileTree(args[0]);
ft.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getPath(); String name = ft.getPathName(path); File file = ft.getFile(path); System.out.println("File " + name + " has been " + (evt.isAddedPath() ? "selected" : "deselected")); System.out.println("File object is " + file); } });
f.getContentPane().add(new JScrollPane(ft)); f.setSize(300, 300); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.setVisible(true); } catch (FileNotFoundException e) { System.out.println("File " + args[0] + " not found"); } } }
vssivl edited on 2004-11-05 18:06
|