Developing Java Beans Now let’s run Example3 again.
Developing Java Beans Now let’s run Example3 again. This time the events are being queued by the PollerAdapter, so the Poller thread can continue running without interference. The following output is generated when the program runs: Value: 3 Received Event Number: 3 Value: 6 Value: 9 Value: 12 Value: 15 Received Event Number: 6 Value: 18 Value: 21 Value: 24 Received Event Number: 9 Value: 27 Value: 30 Value: 33 Received Event Number: 12 Value: 36 Value: 39 Value: 42 Received Event Number: 15 Value: 45 Chapter 4. Properties Properties are named attributes or characteristics. They define the behavior and state of an object. For instance, the current temperature value of the Temperature object is a property, as are the high and low temperature thresholds of the GenericTemperatureThresholdAdapter from the previous chapter. Properties are referenced by their name and can have any type, including primitives such as int, and class and interface types such as java.awt.Color. The name of the low threshold property is LowThreshold, and its type is double. Properties are usually part of the persistent state of an object. This will be dealt with later in Chapter 5. Properties are exposed to visual programming tools and scripting environments, as well as to traditional Java programming. They are manipulated in a visual programming tool through some kind of property-editing interface. In a scripting environment, properties are exposed through a field-style syntax such as Object.Property = value, and value = Object.Property. These are syntactical conveniences provided by the scripting environment. As a Beans developer, you’ll expose your properties as described in the rest of this chapter. 4.1 Accessing Properties An object’s properties are accessed by calling methods that are defined for setting and getting the property value. Any property that can be read will have an associated method for getting its value. Likewise, any property that can be written will have an associated method for setting its value. We’ll see shortly that objects don’t always provide both access mechanisms for every property. Properties can be read/write, read-only, or write-only. The methods used for getting and setting property values should conform to the standard design pattern for properties. These methods are allowed (but not required) to throw checked exceptions. The method signatures are as follows: page 50