• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About multiple listeners!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jamal:
Thanks for ur explain, i see!
reply
    Bookmark Topic Watch Topic
  • New Topic