A sample that demonstrates the handling of the bound bean properties.
This sample program expect the .ini file as a command line argument. If there is no such argument, it use the dwarfs.ini file.
Source code for bean: Dwarf,
import org.ini4j.Ini; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.FileInputStream; public class BeanEventSample { public static final String FILENAME = "dwarfs.ini"; public static void main(String[] args) throws Exception { String filename = (args.length > 0) ? args[0] : FILENAME; Ini ini = new Ini(new FileInputStream(filename)); Dwarf sneezy = ini.get("sneezy").as(Dwarf.class); sneezy.addPropertyChangeListener("age", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { System.out.println("property " + event.getPropertyName() + " change"); System.out.println(event.getOldValue() + " -> " + event.getNewValue()); } }); System.out.println("Sneezy's age: " + sneezy.getAge()); sneezy.setAge(44); System.out.println("Sneezy's age: " + sneezy.getAge()); } }
Standard output:
preference changed: color = blue preference changed: color = gray preference changed: age = 2 Sneezy's age: 64 property age change 64 -> 44 Sneezy's age: 44