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

  • Home
  • SEARCH
  • 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 8370249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:52:14+00:00 2026-06-09T13:52:14+00:00

blueButton.addActionListener(new blueButtonListner()); What happens when this code is entered? What I think is Java

  • 0
blueButton.addActionListener(new blueButtonListner());

What happens when this code is entered?

What I think is Java compiler creates an object called blueButtonListner() and it becomes an input to (parameters for) addActionListener

If that is correct as I guessed then this code should also work:

redButton.addActionListener(rr);
redButtonListener rr =new redButtonListener();

But it shows an error. Can someone explain this to me?

  • 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-09T13:52:15+00:00Added an answer on June 9, 2026 at 1:52 pm

    It’s a matter if precedence, you can’t have something until it’s created

    redButton.addActionListener(rr); redButtonListener rr =new redButtonListener();
    

    Won’t work, because rr hasn’t been defined yet, the compiler has not idea of what it is.

    In contrast

    blueButton.addActionListener(new blueButtonListner())
    

    The compiler creates a temporary Object and passes it to the addActionListener method.

    You can correct your code with this

    redButtonListener rr =new redButtonListener();
    redButton.addActionListener(rr); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For this python 2.7 tkinter code, if I enter 'Apple' and hit the 'Search'
When I run this code in device release mode, it pulls a SIGABRT on
have a little problem with this code: UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
I have some code below that creates a RelativeLayout and adds a button to
I'm receiving the following error message for some code that creates a UIButton. How
I had this working fine while using toggle, but I need to make these
I am trying to fix height for HTML table row. Below is the code
I am teaching myself jquery it seems while working on this project. I assumed
All, Here is my code for a script I am working on. WHAT IT
I know this has been asked a few times here. But none of the

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.