Search code examples
javaeventsarchitecturelisteners

Java basic application architecture


I've just moved into java (from AS3) and I understand the syntax and all the basics, but I can't find any tutorials or books on basic program architecture.

For example,

ObjectA has a property: ObjectB. 
ObjectB has a property: x
ObjectB.x changes at some point. 

How can I have Object A 'catch' or 'hook into' or 'listen for' the change in ObjectB.x?

In AS3, I would make ObjectB an event Dispatcher and have ObjectA listen for some custom Event.

Or in the Flex Framework I would make a changeWatcher.

How is this done in Java and where can I find these architectual basics?


Solution

  • Check out the JavaBeans specification, it includes guidelines on how to create events and listeners so that they conform to the standard (it was standardized because Sun thought there was going to be some Delphi-like market in GUI widgets which never materialized, but it doesn't hurt to have a standard way of doing things). Here's a tutorial on writing event listeners.