This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About multiple listeners!

 
Tony Lee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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!
 
Jamal Hasanov
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Jamal:
Thanks for ur explain, i see!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic