public void testPreferenceChange() { try { Preferences userRoot = Preferences.userRoot(); Preferences node = userRoot.node("testAdd"); node.addPreferenceChangeListener( new PreferenceChangeListener() { public void preferenceChange(PreferenceChangeEvent evt) { System.out.println( " node " + evt.getNode().name() + " key = <" + evt.getKey() + "> val= <" + evt.getNewValue() + ">"); if (evt.getKey().equals("love")) assert evt.getNewValue().equals("ok") : evt.getNewValue(); else if (evt.getKey().equals("love2")) assert evt.getNewValue().equals("not ok") : evt.getNewValue(); } }); node.put("love", "ok"); node.put("love2", "not ok"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } }
public void testNodeChange() { System.out.println("***TestEvent"); try { Preferences userRoot = Preferences.userRoot(); userRoot.addNodeChangeListener( new NodeChangeListener() { public void childAdded(NodeChangeEvent evt) { System.out.println( "childAdded = " + evt.getParent().name() + " " + evt.getChild().name()); } public void childRemoved(NodeChangeEvent evt) { System.out.println( "childRemoved = " + evt.getParent().name() + " " + evt.getChild().name()); } }); Preferences node = userRoot.node("testAdd"); node.removeNode(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } }