• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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!
 
It's exactly the same and completely different as this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic