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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:50:27+00:00 2026-05-26T16:50:27+00:00

My program has one button, and the other one is a JTextField. The action

  • 0

My program has one button, and the other one is a JTextField. The action listener for the button and the textfield are different. I’m using:

textfield.addActionListener(this);
button.addActionListener(this);

… inside my constructor.

They both do the same actionListener. How can I call their respective methods?

  • 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-05-26T16:50:27+00:00Added an answer on May 26, 2026 at 4:50 pm

    You are implementing ActionListener in the class of both components. So, when an action happens, actionPerformed method of the class is called for both of them. You can do following to separate them:

    1-Create a separate class and implement ActionListener interface in it and add it as a actionListener for one of the components.

    2-In actionPerformed method, there is a parameter with ActionEvent type. Call getSource method of it and check if it returns the object of JTextField or JButton by putting an if statement and do separate things accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program has one dialog and two sockets. Both sockets are derived from CAsyncSocket,
I'm making a simple program in Objective-C. It has one class with a lot
I'm trying to make a program in Visual C# that has my one created
The program spits up one of those boxes saying an unhandled exception has occurred
I am trying to create a datapager usercontrol. This user control has one event
My program has to read files that use various encodings. They may be ANSI,
My program has two threads: Main execution thread that handles user input and queues
My program has the following class definition: public sealed class Subscriber { private subscription;
If a program has literally just deserialized an object (doesn't really matter how, but
The data model in my program has a number of discrete states, but I

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.