O'Reilly logo

Core Java® Volume II—Advanced Features, Ninth Edition by Gary Cornell, Cay S. Horstmann

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

10.1.6. An Example: Scripting GUI Events

To illustrate the scripting API, we will write a sample program that allows users to specify event handlers in a scripting language of their choice.

Have a look at the program in Listing 10.1 that adds scripting to an arbitrary frame class. By default it reads the ButtonFrame class in Listing 10.2, which is similar to the event handling demo in Volume I, with two differences:

• Each component has its name property set.

• There are no event handlers.

The event handlers are defined in a property file. Each property definition has the form

componentName.eventName = scriptCode

For example, if you choose to use JavaScript, supply the event handlers in a file js.properties, like this:

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