test

import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.ListSelectionModel; /** * * * @author lee * */ public class FileReseach extends JFrame implements ActionListener { private JList fileList = null; private DefaultListModel model = null; private JScrollPane listScroller = null; private JTextField pathInput = null; private JPanel up = null; private JButton search = null; private String path = null; public FileReseach() { super(); this.setLayout(new BorderLayout()); up = new JPanel(); search = new JButton("Search !"); search.addActionListener(this); pathInput = new JTextField(20); up.add(pathInput); up.add(search); this.add(up, BorderLayout.NORTH); // model = new DefaultListModel(); fileList = new JList(model); fileList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); fileList.setLayoutOrientation(JList.VERTICAL); listScroller = new JScrollPane(fileList); this.add(listScroller, BorderLayout.CENTER); // this.pack(); this.setSize(400, 600); // this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setVisible(true); } public void actionPerformed(ActionEvent arg0) { model.removeAllElements(); path = pathInput.getText(); displayAll(path, ""); // model.addElement("toto"); } /** * * @param path chemin du repertoire courant * @param separator un tab * @see afficher le contenu d'un repertoire recursivement * */ public void displayAll(String path, String separator) { File dir = new File(path); File tmp; String[] list = dir.list(); try { for (String name : list) { tmp = new File(path + "/" + name); if (tmp.isFile() == true) { String str = tmp.getAbsolutePath(); String sep = separator; System.out.println(sep + str); // model.addElement(str+sep); // System.out.println(separator + "->" +str); } else { if (tmp.canExecute()) { System.out.println(separator + name); displayAll(path + "/" + name, " " + separator); } } } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] argv) { FileReseach fr = new FileReseach(); } }

你可能感兴趣的:(import,private,public,休闲,Lee)