File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About multiple listeners! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About multiple listeners!" Watch "About multiple listeners!" New topic
Author

About multiple listeners!

Tony Lee
Greenhorn

Joined: Jan 10, 2002
Posts: 2
can someone explain these points by examples:
� Multiple listeners cause unrelated parts of a program to react to the same event;
� All registered listeners call their handlers when the event occurs;
Thanks!
Jamal Hasanov
Ranch Hand

Joined: Jan 08, 2002
Posts: 411
I'll explain in examples.
• Multiple listeners cause unrelated parts of a program to react to the same event;
• All registered listeners call their handlers when the event occurs;

Think you added 3 Action listetens to button. And when button is clicked, all the methods of listenes will be executed.

Button btn = new Button(“OK” ;
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_actionPerformed1(e);}});
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_actionPerformed2(e);}});
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btn_actionPerformed3(e);}});

When btn button is clicked then, all three functions will be called:
btn_actionPerformed1
btn_actionPerformed2
btn_actionPerformed3
But you can't say in which order they will be called!
That's all.
Jamal
Tony Lee
Greenhorn

Joined: Jan 10, 2002
Posts: 2
Jamal:
Thanks for ur explain, i see!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: About multiple listeners!
 
Similar Threads
Event Handling
Clarification
listeners
event order guarantee?
About event listeners with no adapters...