My program has 8 JButtons and 1 JTextField. Each button should change the text in the text field to something different. I started out having an action listener for each button but i would like to link all the buttons to just 1 action listener and have it recognise which button has been pressed to execute the correct action. any ideas on how this could be done?
surk23
0
Newbie Poster
Recommended Answers
Jump to PostCreate an instance of an object that implements ActionListener.
Add that object as each button's action listener.To recognize which button, use the Event getSource() method.
Jump to PostDeleted
All 6 Replies
NormR1
563
Posting Sage
Team Colleague
NormR1
563
Posting Sage
Team Colleague
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
tong1
22
Posting Whiz
NormR1
563
Posting Sage
Team Colleague
tong1
22
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.