
{filelink=3470}
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
public class ExempleJFileChooser extends JPanel
{
public ExempleJFileChooser(JFrame f) {
final JFrame frame = f;
final JFileChooser chooser = new JFileChooser( );
JButton btnBrows = new JButton("Parcourir...");
add(btnBrows);
btnBrows.addActionListener(new ActionListener( ) {
public void actionPerformed(ActionEvent e) {
int returnVal = chooser.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("Vous avez sélectionné le fichier: " +
chooser.getSelectedFile( ).getPath( ));
} else {
System.out.println("Vous n'avez rien choisi.");
}
}
});
}
public static void main(String[] args) {
JFrame f = new JFrame("Exemple JFileChooser");
f.getContentPane( ).add(new ExempleJFileChooser(f));
f.pack( );
f.setVisible(true);
}
}