Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:26:25+00:00 2026-06-15T13:26:25+00:00

i am doing a browse file class by using JFileChooser. i meet a problem

  • 0

i am doing a browse file class by using JFileChooser. i meet a problem when compile. it keep told me than cannot find symbol actionlistener. below is my code:

import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.text.*;
import javax.swing.filechooser.*;


public class BrowseForFile 
{
private JTextField txtFileName;
private JFrame layout;

public BrowseForFile()
{
    super();
    initialize();
}

    public void initialize() 
    {
        //empty layout
        layout = new JFrame();
        layout.setTitle("Task Synchronization ");
        layout.setBounds(100, 100, 800, 600);
        layout.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        layout.getContentPane().setLayout(null);

        //set the copyright
        JLabel lblNewLabel_5 = new JLabel("(c) 2012 All Rights Reserved");
        lblNewLabel_5.setForeground(Color.GRAY);
        lblNewLabel_5.setFont(new Font("Tahoma", Font.PLAIN, 10));
        lblNewLabel_5.setHorizontalAlignment(SwingConstants.RIGHT);
        lblNewLabel_5.setBounds(527, 548, 255, 14);
        layout.getContentPane().add(lblNewLabel_5);

        //set the label
        JLabel lblSendAFile = new JLabel("Select a file to be sent to all nodes");
        lblSendAFile.setBounds(404, 400, 378, 14);
        layout.getContentPane().add(lblSendAFile);

        //set the textfield
        txtFileName = new JTextField();
        txtFileName.setBounds(404, 425, 277, 20);
        layout.getContentPane().add(txtFileName);
        txtFileName.setColumns(10);

        //set the browse button and let it to choose file after click.
        JButton btnBrowse = new JButton("Browse");
        btnBrowse.setBounds(691, 424, 91, 23);
        layout.getContentPane().add(btnBrowse);

        btnBrowse.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                JFileChooser chooser = new JFileChooser();
                chooser.setCurrentDirectory(new File(dirName));
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

                FileNameExtensionFilter filter = new FileNameExtensionFilter(".txt only", "txt");
                chooser.setFileFilter(filter);

                try {
                int code = chooser.showOpenDialog(null);
                if (code == JFileChooser.APPROVE_OPTION) {
                File selectedFile = chooser.getSelectedFile();
                Scanner input = new Scanner(selectedFile); 
                String f=selectedFile.getName();
                txtFileName.setText("File Name is: "+f);



                }

                } catch (Exception f) {
                f.printStackTrace();
                }
            }
        });
    }







    public static void main(String[] args)
    {
        try 
        {
            BrowseForFile window = new BrowseForFile();
            window.layout.setVisible(true);
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }
    }


}

this is the error :

BrowseForFile.java:52: error: cannot find symbol
                    btnBrowse.addActionListener(new ActionListener()
                                                    ^
symbol:   class ActionListener
location: class BrowseForFile
1 error

can anyone tell me what is the error ? thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:26:26+00:00Added an answer on June 15, 2026 at 1:26 pm
    import java.awt.event.ActionListener; // seems to be missing.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
I'm just starting with jQuery, and having trouble doing something embarrassingly simple: using .load()
I am using the multi-upload plugin found at: http://www.fyneworks.com/jquery/multiple-file-upload/ This is what I am
I am using the following php class to convert text to speech: http://www.masnun.me/2009/12/14/googles-text-to-speech-api-a-php-wrapper-class.html its
I've got a simple HTML file upload form. I'm using the jQuery validation plugin
I'm building a html table dynamically in an ASP.NET code behind file using C#.
I am using a listener class with ReportNG to capture screenshot of failed test
I want to send a csv file from Android to Python AppEngine. I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.