• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

About event listeners with no adapters...

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just remember A.I.T., any of the event listeners starting with these letters dont have adapters (there is one more, but most likely not on the exam).
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The low-level event listeners are the ones that have adapters because those listeners have multiple methods, not all of which you may want to implement.
The high level event listeners (ActionListener, AdjustmentListener, ItemListener, and TextListener) only have one method each, so there is no reason to provide an adapter class.
Corey
 
Joshua Kueck
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yaya.. dis I know.. dis I know.. but this is for those who are rushing.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,
when we add an anonymous object to listen to an event say ActionEvent, why do we write
Button b;
b.addActionListener( new ActionListener() {..});
i.e when ActionListener is an interface, how can we write new ActionListener().
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In such a case, you're not really creating a new ActionListener (as that's impossible). Rather, a new anonymous class is created that extends Object and implements ActionListener. That's the object that really gets created.
If you were to add this line inside the ActionListener object:

You'd see something like this getting printed out (assuming that the class MyFrame is where this ActionListener is created):

Notice, it doesn't have a type of ActionListener, it is actually an inner class of the class MyFrame and it is assigned a class name of 1.
I hope that helps,
Corey
 
Akhilesh Varma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey,
Thanks a lot..i guess i was confused because of the new ActionListener () syntax.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you mentioned that you just bought Rasmussen and Mughal in your other post, flip to page 245 for a discussion of what is happening in this situation.
Corey
 
please buy my thing and then I'll have more money:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic