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 8190215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:32:51+00:00 2026-06-07T03:32:51+00:00

When I compile it show error in line 33 : Cannot find symbol. I

  • 0

When I compile it show error in line 33 : Cannot find symbol.
I am calling jbtNew.addActionListener(listener), so why it’s unable to find jbtNew in

(e.getSource() == jbtNew) in line 33.

from code

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class AnonymousListenerDemo extends JFrame {

    public AnonymousListenerDemo() {
        // Create four buttons
        JButton jbtNew = new JButton("New");
        JButton jbtOpen = new JButton("Open");
        JButton jbtSave = new JButton("Save");
        JButton jbtPrint = new JButton("Print");
        // Create a panel to hold buttons
        JPanel panel = new JPanel();
        panel.add(jbtNew);
        panel.add(jbtOpen);
        panel.add(jbtSave);
        panel.add(jbtPrint);

        add(panel);
        // Create and register anonymous inner-class listener
        AnonymousListenerDemo.ButtonListener listener = new AnonymousListenerDemo.ButtonListener();
        jbtNew.addActionListener(listener);


    }

    class ButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == jbtNew) //Here it show the problem
            {
                System.out.println("Process New");
            }
        }
    }

    /** Main method */
    public static void main(String[] args) {
        JFrame frame = new AnonymousListenerDemo();
        frame.setTitle("AnonymousListenerDemo");
        frame.setLocationRelativeTo(null); // Center the frame
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
  • 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-07T03:32:54+00:00Added an answer on June 7, 2026 at 3:32 am

    this could be work (in the form as you posted here) and @SLaks mentioned +1, with a few major changes

    in the case that all methods will be placed into separated classes to use put/getClientProperty()

    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class AnonymousListenerDemo {
    
        private static final long serialVersionUID = 1L;
        private JFrame frame = new JFrame("AnonymousListenerDemo");
        // Create four buttons
        private JButton jbtNew = new JButton("New");
        private JButton jbtOpen = new JButton("Open");
        private JButton jbtSave = new JButton("Save");
        private JButton jbtPrint = new JButton("Print");
    
        public AnonymousListenerDemo() {
            JPanel panel = new JPanel();// Create a panel to hold buttons
            panel.add(jbtNew);
            panel.add(jbtOpen);
            panel.add(jbtSave);
            panel.add(jbtPrint);
            // Create and register anonymous inner-class listener
            jbtNew.addActionListener(new ButtonListener());
            frame.add(panel);
            //frame.setTitle("AnonymousListenerDemo");
            frame.setLocationRelativeTo(null); // Center the frame
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        }
    
        class ButtonListener implements ActionListener {
    
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == jbtNew) {
                    System.out.println("Process New");
                }
            }
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                public void run() {
                    new AnonymousListenerDemo();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot compile the following code: main = do line <- getLine putStrLn (work
When I try to compile code on VS 2005 and it fails, the line
When I try to compile to following code, I get two errors: Description Resource
Possible Duplicate: Convert some code from C++ to C I've got some code that
Basically it is the following code, which cannot pass compiler (g++) #include <boost/program_options.hpp> #include
In the Below action script file there is an error saying cannot import mx.controls.Label,
I can see line numbers in my error logs in our development environment, in
I get this error when I load my video show view: SyntaxError in Videos#show
I'm building a controller to show the data from a custom object on a
i use the command line in windows to compile and then execute my java

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.