Hey all.I got a question about the use of action listeners.Actually its more about actionEvents.Anyway,my question is: Supposing i have a frame with four buttons,say "A","B","C","D". I want each time i press a different button something different to appear on TextField.I know i can make 4 different button subclasses,each with a different actionPerformed.Or i can make 4 different actionListeners.But i wonder if there is a simpler way to do that,in case i eg have 40 buttons. Can i somehow find out what was the "actionEvent" aka which of the same-but differently named-buttons was pushed?Thanks!
chester1908
0
Newbie Poster
Recommended Answers
Jump to PostHi, I think that you can get the button that was clicked using the source property of the ActionEvent object that you receive inside your listener.
Also you can create a subclass of Button with a property that contains the text that you want to appear on the TextField.
…
Jump to Posthttp://download.oracle.com/javase/tutorial/uiswing/components/button.html
http://download.oracle.com/javase/tutorial/uiswing/events/actionlistener.html
"But i wonder if there is a simpler way to do that,in …
All 5 Replies
komyg
0
Light Poster
mKorbel
274
Veteran Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
chester1908
0
Newbie Poster
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.