• 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

Delegation event model.

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it true for delegation event madel?
"when a listener receives an event a copy of original event is
passed into a listener method."
I found it false in a mockexam but I think it is true.
e.g.void actionPerformed(ActionEvent x){} has a parameter 'ActionEvent', to invoke this method actionListener must pass
a copy of the event.
Please someone verify this.
Nasir.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nasir.
I feel the answer is false, as whenever you pass any object to any method, the reference is passed not the orginal object.
Pls correct me if i am wrong.
Regards
Prasad
------------------
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java , Objects are used by Object Reference.Also to functionsarguments are passes by value.Refering to the above example , a copy is made of the reference to the ActionEvent object and is passed to the actionPerformed function and not the copy of the ActionEvent object.
I think this suits you
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Grish and parsad
consider this
1 String x=new String("mystring");
2 amethod(x);
line1 creats a string object and x is a referance to that object
line2 calls amethod and a copy of x is sent to the method as parameter
now consider this
acomponent.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {}});
I have a little doubt here .
When a action(of ActionEvent type) is
performed what does ActionListener receives?
As I understood from your explaination it should receive
a referance to that action event object(like x which refers to
a String object on line1)
Then actionPerformed is called with a copy of that referance
(just like line2)

Am i right?
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nasir Khan:
[B]consider this
1 String x=new String("mystring");
2 amethod(x);
line1 creats a string object and x is a referance to that object
line2 calls amethod and a copy of x is sent to the method as parameter


What is being passed is a copy of the reference, not copy of the object. Both the references point to the same object. Therefore if it were a object like StringBuffer then any change to that onbect via the copied reference would change it.
HTH,
Shubhangi
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer for the original answer is false. Simply for the reason because a listener may not be called with the original object. Since events are immutable(by and large not strictly, as some events have consume() method which set the flag), which sometimes causes a event handler or event generator (or some intermediate handler) to pass the event by setting some new parameter. Which might lead that the final listener may not get the original event.


I hope that clears.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic