Below is the output of the "hello world" application written using WTKX. Note that, with the exception of the actual text, it is identical to the output of the Java version:
The following is the Java source code for the WTKX version. The content of the user interface is defined entirely by the WTKX source file. It is loaded using an instance of the WTKXSerializer class defined in the org.apache.pivot.wtkx package.
package org.apache.pivot.tutorials; import org.apache.pivot.collections.Map; import org.apache.pivot.wtk.Application; import org.apache.pivot.wtk.DesktopApplicationContext; import org.apache.pivot.wtk.Display; import org.apache.pivot.wtk.Window; import org.apache.pivot.wtkx.WTKXSerializer; public class HelloWTKX implements Application { private Window window = null; public void startup(Display display, Map<String, String> properties) throws Exception { WTKXSerializer wtkxSerializer = new WTKXSerializer(); window = (Window)wtkxSerializer.readObject(this, "hello.wtkx"); window.open(display); } public boolean shutdown(boolean optional) { if (window != null) { window.close(); } return false; } public void suspend() { } public void resume() { } public static void main(String[] args) { DesktopApplicationContext.main(HelloWTKX.class, args); } }
The WTKX that is used to create the UI is shown below:
<Window title="Hello WTKX!" maximized="true" xmlns:wtkx="http://pivot.apache.org/wtkx" xmlns="org.apache.pivot.wtk"> <content> <Label text="Hello WTKX!" styles="{font:'Arial bold 24', color:'#ff0000', horizontalAlignment:'center', verticalAlignment:'center'}"/> </content> </Window>
Most Pivot applications will be constructed this way, by declaring the structure of the UI in WTKX rather than in Java. However, event handlers, which allow an application to respond to user input, are often defined in Java (though they can also be defined within script blocks in the WTKX file). Event handlers are discussed in more detail in later sections.
Next: Component & Container