DefaultObjectHandler |
From JAXXWiki
The class jaxx.tags.DefaultObjectHandler provides the base support for all JAXX class tags. DefaultObjectHandler uses introspection to examine the properties and events of a class and offer support for them via XML attributes.
Contents |
Properties
A property of an object is a value that can be read using a get method and (optionally) set using a set method. For example, the methods getText() and setText() of the class javax.swing.JLabel together comprise a property named text.
DefaultObjectHandler provides support for setting the value of all writable properties via attributes. The attribute assignment is compiled into a call to the appropriate set method.
<JLabel text='Example Label'/>
This is equivalent to the following Java code:
JLabel label = new JLabel();
label.setText("Example Label");
Type conversions
XML attribute values are always strings. For string-typed properties, such as JLabel's text property in the example above, the attribute value can be used directly. For other types of properties, the value must be converted from a string to the appropriate type. Full documentation on this conversion process can be found at data types.
Event Handlers
An event handler is an attribute containing Java code that runs when an event fires. The name of the attribute must begin with "on" followed by a capital letter. Events are named according to the methods in their listener interfaces, such that the MouseListener interface corresponds to five events: onMouseClicked, onMouseEntered, onMouseExited, onMousePressed, and onMouseReleased.
The value of an event listener must be valid Java code which could appear in a method body. The code runs in the context of the overall JAXX class, so that its this reference is the component created by the root tag, not the tag in which it appears. The event object is stored as the variable event.
Example:
<JFrame title='Event Handler Example'>
<JButton label='Close' onActionPerformed='System.out.println("Closing due to: " + event); dispose()'/>
</JFrame>

