1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public JButton getOuvrirSource() {
if (OuvrirSource == null){
OuvrirSource = new JButton(". . .");
OuvrirSource.setBounds(530, 40, 40, 22);
OuvrirSource.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
fc = new JFileChooser(TxtRepSource.getText());//recupération du chemin
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);//Seul le répertoire est selectionné ici
//fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int returnVal = fc.showOpenDialog(FILExpert.this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
ChoosedFile = fc.getSelectedFile().getPath();//Le chemin est récupéré ici
TxtRepSource.setText(ChoosedFile);
File fichier1 = new File(ChoosedFile);
if (fichier1.isDirectory()){
String str[] = fichier1.list();
for (int i=0; i<str.length; i++){
File fichier2 = new File (ChoosedFile + "/" + str[i]);
if (fichier2.isDirectory()){
System.out.println("Répertoire :" + str[i]);
}
else{
System.out.println(str[i]);
}
}
}
}
}
});
}
return OuvrirSource;
} |
Partager