Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Custom event

Thread view: 
Suma Shanbhog - 05 Sep 2006 09:20 GMT
Hello All,

How can I write a custom event?
I want to create a custom event object and fire it at a particular point in
program.

Thanks in advance!

Regards
Suma
VisionSet - 05 Sep 2006 10:17 GMT
> Hello All,
>
[quoted text clipped - 3 lines]
>
> Thanks in advance!

public class MyEvent {}

public interface MyListener {
 void eventFired(MyEvent evt);
}

public class AnObservable {
 private List<MyListener> listeners;

 public void fire() {
   for (MyListener ml : listeners) ml.fire(new MyEvent());
 }

 public void addListener(MyListener ml) {
   listener.add(ml);
 }
}

public class AnObserver {
 private MyListener myListener = new MyListener() {
   public void eventFired(MyEvent evt) {
       // react to event being fired
   }
 };
}
Suma Shanbhog - 06 Sep 2006 06:57 GMT
After a lot of exercise I managed to do it....

Thanks a lot!
Suma

> > Hello All,
> >
[quoted text clipped - 30 lines]
>   };
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.