Win a copy of The Java Performance Companion this week in the Performance 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
Posts: 21124
32
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
Pie
Posts: 49382
62
  • 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: 20546
57
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