Google Web Toolkitについて2
Google Web Toolkitは次のようにして試すことが出来る。
- 新規プロジェクトで 動的Webプロジェクト を作成するときの構成とし Cypal Studio GWT Project を指定して作成
プロジェクト名:HelloGWT
または既存プロジェクトの場合はプロジェクト・ファセットに Cypal's GWT Facetを追加
- 新規ファイルで Cypal Studio の「モジュール」を選んで作成
パッケージ名: tutorial.gwt 名前:MyGWT
これで
tutorial/gwt/public/MyGWT.html -- サンプルのHTML tutorial/gwt/client/MyGWT.java -- クライアントコード用のメインJAVA
あともろもろできるが触る必要ないので省略
が、できる。
例えば、ボタンをクリックするたびにテキストをカウントアップしていく単純なコードは
- MyGWT.java を次のようにする
package tutorial.gwt.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; public class MyGWT implements EntryPoint { Label lbl = new Label(""); int cnt =0; public void onModuleLoad() { Button btn = new Button("Click!"); btn.addClickListener( new ClickListener() { public void onClick(Widget arg0) { lbl.setText( ""+cnt++ ); } }); RootPanel.get("slot1").add(btn); RootPanel.get("slot1").add(lbl); } }
あと、MyGWT.html の body のどこかに
<div id="slot1"/>
を追加(これは GWTが RootPanelからgetする場所のマークとなる)
そして、GWT Hosted Mode Applicationで今のプロジェクトとモジュールを指定して実行すれば、Google Web Toolkit Development Shellが起動して、実行される。
そのウインドウの Compile/Browse ボタンを押すとCompileされ、プロジェクトを更新すると
Tomcatを起動すれば
http://localhost/HelloGWT/MyGWT.html でブラウザで確認することが出来る。
GWTの単体動作はこれでOK