This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create user defined and customized call back method in core java?

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to create user defined and customized call back method in core java??
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you be more specific?
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If want to create any user define Session listener then I have implement Session listener Interface, Like that, in swing, Mouse listener, we have to implement listener interface sun provided

But I do not want theirs listener and want to own listener, how it can be created??
 
Paul Clapham
Sheriff
Pie
Posts: 20768
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would do it basically the same way as those interfaces you mentioned do it. What part of this are you having trouble with?
 
Campbell Ritchie
Sheriff
Posts: 48441
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think callbacks are a "beginning" question. Moving thread.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The event listener frame work works as follows:
- Create a subclass of EventObject (or any of its subclasses like ActionEvent), let's call it MyEvent
- Create a subinterface of EventListener (or any of its subinterfaces like ActionListener), let's call it MyListener
- Give MyListener one method for each type of event with MyEvent as the parameter:

- If your listener has more than one method and you like your users, create an adapter with empty-body implementations:
That way, users only need to override the methods they need to implement.

As for calling the listeners, there are two ways:
1) use a List<MyListener>:
2) use an EventListenerList:
I'd go for EventListenerList if you need more than one listener type.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic