在以下的範例(由官網取得)中,使用了org.apache.pivot.wtk.content.ButtonData物件來描述按鈕的文字及圖示(icon)。
============範例展示=================================================
============範例展示=================================================
<!--ui.bxml--> <Window title="Toggle Buttons" maximized="true" xmlns:bxml="http://pivot.apache.org/bxml" xmlns:content="org.apache.pivot.wtk.content" xmlns="org.apache.pivot.wtk"> <BoxPane styles="{padding:4, horizontalAlignment:'center', verticalAlignment:'center'}"> <PushButton toggleButton="true"> <content:ButtonData text="下錨?" icon="/anchor.png"/> </PushButton> <PushButton toggleButton="true"> <content:ButtonData text="杯子?" icon="/cup.png"/> </PushButton> <PushButton toggleButton="true"> <content:ButtonData text="星星?" icon="/star.png"/> </PushButton> </BoxPane> </Window>
注意在BXML中的icon設定值,它是由/開始,表示會從整個應用程式中classpath的相對位置來尋找檔案,若是以@開始,則表示由此一bxml檔案所在地為相對位置。
Java原始碼:
//NewClass.java import java.awt.Font; import org.apache.pivot.beans.BXMLSerializer; import org.apache.pivot.collections.Map; import org.apache.pivot.wtk.*; public class NewClass implements Application { private Window window = null; public static void main(String[] args) { DesktopApplicationContext.main(NewClass.class, args); } @Override public void startup(Display display, Map<String, String> properties) throws Exception { Theme.getTheme().setFont(new Font("PMingLiU",Font.PLAIN,12)); BXMLSerializer bxmlSerializer = new BXMLSerializer(); window = (Window) bxmlSerializer.readObject(NewClass.class, "ui.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