In addition to describe what components to create in ZUML pages, developers could create them manually. All component classes are concrete. You create them directly[15] with their constructors.
<window id="main"> <button label="Add Item"> <attribute name="onClick"> new Label("Added at "+new Date()).setParent(main); new Separator().setParent(main); </attribute> </button> <separator bar="true"/> </window>
When a component is created manually, it won't be added to any page automatically. In other words, it doesn't appear at user's browser. To add it to a page, you could invoke the setParent, appendChild or insertBefore method to assign a parent to it, and it becomes a part of a page if the parent is a part of a page.
There is no destroy or close method for components[16]. A component is removed from the browser as soon as it is detached from the page. It is shown as soon as it is attached to the page.
<window id="main"> <zscript>Component detached = null;</zscript> <button id="btn" label="Detach"> <attribute name="onClick"> if(detached != null) { detached.setParent(main); detached = null; btn.label = "Detach"; } else { (detached = target).setParent(null); btn.label = "Attach"; } </attribute> </button> <separator bar="true"/> <label id="target" value="You see this if it is attached."/> </window>
In the above example, you could use the setVisible method to have a similar effect. However, setVisible(false) doesn't remove the component from the browser. It just makes a component (and all its children) invisible.
After a component is detached from a page, the memory it occupies is release by JVM's garbage collector if the application has no reference to it.