Wednesday, July 11, 2012

LinkButton

本範例將結合CardPane以及Link Button達成圖片瀏覽的功能。CardPane就如同一疊卡片一般,同一時間只能顯示一張卡片,詳細留待往後說明。本範例由官網取得。

在此ui.bxml中,使用了另一種事件處理機制,用<buttonPressListeners></buttonPressListeners>,也就是將要進行的事件處理撰寫在<buttonPressListeners></buttonPressListeners>區塊中。在範例中所寫的處理機制是要設定選擇了在CardPane中的哪一個card。



============範例展示=================================================


============範例展示=================================================

<!--ui.bxml-->
<Window title="Link Buttons" maximized="true"
        xmlns:bxml="http://pivot.apache.org/bxml"
        xmlns:content="org.apache.pivot.wtk.content"
        xmlns="org.apache.pivot.wtk">
    <Border>
        <CardPane bxml:id="cardPane" selectedIndex="0" styles="{selectionChangeEffect:'horizontal_slide'}">
            <BoxPane orientation="vertical" styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
                <ImageView image="/IMG_0735_2.jpg"/>
                <LinkButton>
                    <content:ButtonData text="下一張" icon="@resultset_next.png"/>
 
                    <buttonPressListeners>
                        function buttonPressed(button) {
                        cardPane.setSelectedIndex(1);
                        }
                    </buttonPressListeners>
                </LinkButton>
            </BoxPane>
 
            <BoxPane orientation="vertical" styles="{horizontalAlignment:'center', verticalAlignment:'center'}">
                <ImageView image="/IMG_0767_2.jpg"/>
                <LinkButton>
                    <content:ButtonData text="上一張" icon="@resultset_previous.png"/>
 
                    <buttonPressListeners>
                        function buttonPressed(button) {
                        cardPane.setSelectedIndex(0);
                        }
                    </buttonPressListeners>
                </LinkButton>
            </BoxPane>
        </CardPane>
    </Border>
</Window>

最後仍然是NewClass.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