| <?xml version="1.0" encoding="UTF-8"?> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to you under the Apache License, |
| Version 2.0 (the "License"); you may not use this file except in |
| compliance with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <document id="radio-buttons"> |
| <properties> |
| <title>Radio Buttons</title> |
| </properties> |
| |
| <body> |
| <p> |
| The following example demonstrates how to use the <tt>RadioButton</tt> class in a |
| Pivot application: |
| </p> |
| |
| <application class="org.apache.pivot.wtk.ScriptApplication" |
| width="480" height="360"> |
| <libraries> |
| <library>core</library> |
| <library>wtk</library> |
| <library>wtk-terra</library> |
| <library>tutorials</library> |
| </libraries> |
| <startup-properties> |
| <src>/org/apache/pivot/tutorials/buttons/radio_buttons.bxml</src> |
| </startup-properties> |
| </application> |
| |
| <p> |
| The BXML source for the example is below: |
| </p> |
| |
| <source type="xml" location="org/apache/pivot/tutorials/buttons/radio_buttons.bxml"> |
| <![CDATA[ |
| <buttons:RadioButtons title="Radio Buttons" maximized="true" |
| xmlns:bxml="http://pivot.apache.org/bxml" |
| xmlns:buttons="org.apache.pivot.tutorials.buttons" |
| xmlns="org.apache.pivot.wtk"> |
| <Border> |
| <BoxPane orientation="vertical" styles="{padding:4}"> |
| <bxml:define> |
| <ButtonGroup bxml:id="numbers"/> |
| </bxml:define> |
| <RadioButton bxml:id="oneButton" buttonData="One" buttonGroup="$numbers" selected="true"/> |
| <RadioButton bxml:id="twoButton" buttonData="Two" buttonGroup="$numbers"/> |
| <RadioButton bxml:id="threeButton" buttonData="Three" buttonGroup="$numbers"/> |
| <PushButton bxml:id="selectButton" buttonData="Select"/> |
| </BoxPane> |
| </Border> |
| </buttons:RadioButtons> |
| ]]> |
| </source> |
| |
| <p> |
| The following is the Java source for the example. Like the push button example, the |
| application registers an event listener that is called when the button is pressed. |
| It also gets a reference to a button group named <tt>numbersGroup</tt> |
| (<tt>numbersGroup</tt> is defined as a final local variable so the handler method will |
| have access to it). When called, the handler gets a reference to the currently selected |
| button from the button group and displays an alert containing the data of the selected |
| button. |
| </p> |
| |
| <source type="java" location="org/apache/pivot/tutorials/buttons/PushButtons.java"> |
| <![CDATA[ |
| package org.apache.pivot.tutorials.buttons; |
| |
| import java.net.URL; |
| |
| import org.apache.pivot.beans.Bindable; |
| import org.apache.pivot.collections.Map; |
| import org.apache.pivot.util.Resources; |
| import org.apache.pivot.wtk.Alert; |
| import org.apache.pivot.wtk.Button; |
| import org.apache.pivot.wtk.ButtonGroup; |
| import org.apache.pivot.wtk.ButtonPressListener; |
| import org.apache.pivot.wtk.MessageType; |
| import org.apache.pivot.wtk.PushButton; |
| import org.apache.pivot.wtk.Window; |
| |
| public class RadioButtons extends Window implements Bindable { |
| private PushButton selectButton = null; |
| |
| @Override |
| public void initialize(Map<String, Object> namespace, URL location, Resources resources) { |
| selectButton = (PushButton)namespace.get("selectButton"); |
| |
| // Get a reference to the button group |
| final ButtonGroup numbersGroup = (ButtonGroup)namespace.get("numbers"); |
| |
| // Add a button press listener |
| selectButton.getButtonPressListeners().add(new ButtonPressListener() { |
| @Override |
| public void buttonPressed(Button button) { |
| String message = "You selected \"" |
| + numbersGroup.getSelection().getButtonData() |
| + "\"."; |
| Alert.alert(MessageType.INFO, message, RadioButtons.this); |
| } |
| }); |
| } |
| } |
| ]]> |
| </source> |
| </body> |
| </document> |