The Artima Developer Community
Sponsored Link

Java Answers Forum
Raising Events from Classes

1 reply on 1 page. Most recent reply: Jan 18, 2003 10:02 AM by Ugo Posada

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Roy

Posts: 1
Nickname: royboy
Registered: Jan, 2003

Raising Events from Classes Posted: Jan 16, 2003 9:21 AM
Reply to this message Reply
Advertisement
Hi,

After working with VB6 for sometime I discovered the ?RaiseEvent? statement and found it to be very useful in creating classes that were abstract and could be reused easily. This allows objects to communicate to their parent objects (the objects that have instantiated a specific object) that something has happened within the object.

As I?m designing a real time model of a train in Java I need to be able to inform parent objects of events within other objects.

For example, in VB6 I have already created the train model with heavy use of events. In one particular subclass, the ?Engine? class fires off an event where it?s RPM (revs per minute) has changed. The beauty of this is that the object instantiated as class engine does not need to know about all other objects using it, but all objects using it can handle the fired event if they have a method declared to use it. I think this might be polymorphism, but I?m not sure.

Does Java allow this? Im aware of events in the awt package, but im not interested in those. I need to be able to create my own custom events.


Ugo Posada

Posts: 37
Nickname: binaryx
Registered: Dec, 2002

Re: Raising Events from Classes Posted: Jan 18, 2003 10:02 AM
Reply to this message Reply
Check out interface observer and class observable. Very quickly, a class tha extends observable has a list of classes that are aware of what is happening to it (Classes that implement observer), that is, every time something changes in this class all the observers of the behavior are notified so they can do whatever they want to do, for instance, updating a view, it is very used with the MVC pattern.

Flat View: This topic has 1 reply on 1 page
Topic: Urgent Help needed Previous Topic   Next Topic Topic: package   BUG !! ??

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use