O'Reilly logo

Developing Java Beans by Robert Englander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required