本文將介紹簡易的BXML使用法。在java原始碼中,必須使用BXMLSerializer來將bxml中的UI設定轉化為java中的UI物件,並且讀入bxml後必須再將物件進行強迫轉型,將物件轉為org.apache.pivot.wtk.Window物件。
============範例展示=================================================
============範例展示=================================================
以下為hello.bxml的UI設定,只有顯示一個Label,並且以新細明體(PMingLiU)來顯示中文字!
<Window title="Hello BXML!" maximized="true" xmlns:bxml="http://pivot.apache.org/bxml" xmlns="org.apache.pivot.wtk"> <Label text="Hello BXML!使用中文顯示!新細明體!" styles="{font:'PMingLiU bold 24', color:'#ff0000', horizontalAlignment:'center', verticalAlignment:'center'}"/> </Window>
接下來則是java原始碼:
import org.apache.pivot.beans.BXMLSerializer; 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; public class HelloBXML implements Application { private Window window = null; public static void main(String[] args) { DesktopApplicationContext.main(HelloBXML.class, args); } @Override public void startup(Display display, Map<String, String> properties) throws Exception { BXMLSerializer bxmlSerializer = new BXMLSerializer(); window = (Window) bxmlSerializer.readObject(HelloBXML.class, "hello.bxml"); window.open(display); } @Override public boolean shutdown(boolean optional) { if (window != null) { window.close(); } return false; } @Override public void suspend() { } @Override public void resume() { } }
No comments:
Post a Comment