ラジオボタン・チェックボックス

GwtUISampleRadioCheck.java

package sample.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class GwtUISampleRadioCheck implements EntryPoint {
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		CheckBox checkbox = new CheckBox("チェックボックス");
		checkbox.setValue(true);
		final Label lb_check = new Label("チェックボックスの状態");
		RootPanel.get("checkbox").add(checkbox);
		RootPanel.get("checked").add(lb_check);
		
		RadioButton radio_1 = new RadioButton("radio_1");
//		radio_1.setValue(true);
		final Label lb_radio = new Label("ラジオボタンの状態");
		RootPanel.get("radiobutton").add(radio_1);
		RootPanel.get("radiochecked").add(lb_radio);
		
		checkbox.addValueChangeHandler(new ValueChangeHandler<Boolean>(){
		
			@Override
			public void onValueChange(ValueChangeEvent<Boolean> event) {
				System.out.println(event.getValue());
				lb_check.setText(event.getValue().toString());
//				boolean checked = ((Checkbox)event).getValue();				
			}
		});
		
		radio_1.addValueChangeHandler(new ValueChangeHandler<Boolean>(){

			@Override
			public void onValueChange(ValueChangeEvent<Boolean> event) {
				lb_radio.setText(event.getValue().toString());
			}
			
		});
	}
}

GwtUISampleRadioCheck.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
<!-- above set at the top of the file will set     -->
<!-- the browser's rendering engine into           -->
<!-- "Quirks Mode". Replacing this declaration     -->
<!-- with a "Standards Mode" doctype is supported, -->
<!-- but may lead to some differences in layout.   -->

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <!--                                                               -->
    <!-- Consider inlining CSS to reduce the number of requested files -->
    <!--                                                               -->
    <link type="text/css" rel="stylesheet" href="GwtUISampleRadioCheck.css">

    <!--                                           -->
    <!-- Any title is fine                         -->
    <!--                                           -->
    <title>Web Application Starter Project</title>
    
    <!--                                           -->
    <!-- This script loads your compiled module.   -->
    <!-- If you add any GWT meta tags, they must   -->
    <!-- be added before this line.                -->
    <!--                                           -->
    <script type="text/javascript" language="javascript" src="gwtuisampleradiocheck/gwtuisampleradiocheck.nocache.js"></script>
  </head>

  <!--                                           -->
  <!-- The body can have arbitrary html, or      -->
  <!-- you can leave the body empty if you want  -->
  <!-- to create a completely dynamic UI.        -->
  <!--                                           -->
  <body>

    <!-- OPTIONAL: include this if you want history support -->
    <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

    <h1>Web Application Starter Project</h1>

    <table align="center">
      <tr>
        <td colspan="2" style="font-weight:bold;">UISample radio & check</td>        
      </tr>
      <tr>
        <td id="checkbox"></td>
        <td id="checked"></td>
       </tr>
       <tr>
        <td id="radiobutton"></td>
        <td id="radiochecked"></td>
      </tr>
    </table>
  </body>
</html>