Evento click ao botão e uso da classe JFileChooser

estou com um pequeno problema, estou com um problema para usar o evento click do botão e carregar um JFileChooser,
se alguém puder me ajudar obrigado.

package buscapalavra;

/**
*

  • @author Dellandre
    /
    import javax.swing.
    ;
    import javax.swing.JPanel.*;
    import javax.swing.JLabel;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class frmBuscaPalavra {

    /** Creates a new instance of frmBuscaPalavra */
    public void frmBuscaPalavra() {
    JLabel label = new JLabel(“Diretório:”);
    JLabel label2 = new JLabel(“Palavra:”);
    JTextField diretorio = new JTextField(20);
    JTextField palavra = new JTextField(10);
    JButton localizar = new JButton(“Buscar”);
    JButton pesquisar = new JButton (“Pesquisar”);
    JPanel painel = new JPanel();
    JFrame frmBusca = new JFrame();

     pesquisar.addActionListener(this);
     
     
     /** adicionando objetos ao painel */
     
     painel.add(label);
     painel.add(diretorio);
     painel.add(label2);
     painel.add(palavra);
     frmBusca.add(painel);
     frmBusca.setVisible(true);
    

    }

    public void actionPerformed(ActionEvent e)
    {
    if(e.getSource() == pesquisar)
    {
    JFileChooser jFC = new JFileChooser();
    jFC.setVisible(true)
    }
    }
    }

se puder me mostrar como carregar essa classe na classe main para que o formulário possa aparecer, agradeço desde já.

Segue um exemplo:

JButton button = new JButton("Escolha um Arquivo"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JFileChooser fileChooser = new JFileChooser(); int returnValue = fileChooser.showOpenDialog(null); if (returnValue == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); System.out.println(selectedFile.getName()); } } });

vlw kra funcionou sim, muito obrigado

Agora outro problema.

Como faço para mandar o diretório gerado pelo JFileChooser para uma JTextField fora do metodo, se alguém puder me ajudar quanto a isso.

seuTextField.setText(seuFileChooser.getSelectedFile().getPath());