Hooking Up Beans

Beans are hooked up to each other by matching event sources to methods on the target Bean. The BeanBox does not hook event sources directly to event targets. Instead, BeanBox generates Java code for a specialized adapter. This allows BeanBox to match event sources to target methods that are not necessarily designed specifically for handling that event. For instance, we already know that we could match an actionEvent source Bean with one that implements the ActionEventListener interface through its actionPerformed() method. But BeanBox uses a more flexible approach. It allows you to map the action event to a variety of target methods. The custom adapter code that is generated handles the specifics. We’ll look at the Java code for a hookup adapter a little later.

Let’s look at some examples. Drop two instances of the ExplicitButton Bean onto the form, along with an instance of Juggler. Change the label property of the Beans named ExplicitButton so that one of them is Start and the other is Stop. The Juggler Bean is an animation Bean that shows the Java mascot juggling some coffee beans. The animation can be started and stopped by invoking the Bean’s startJuggling() and stopJuggling() methods, respectively. We use the buttons to invoke these methods. We hook up various events and methods of these Beans to examine the way BeanBox works, as well as the adapter code that it generates. Figure 7.8 shows what the BeanBox form looks like with the Beans that we dropped on ...

Get Developing Java Beans now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.