隨筆:25 文章:1 評論:66 引用:0
steeven
BlogJava
首頁
發新隨筆
發新文章
聯系
聚合
管理
GWT做的guess number
gwt的這些特性還是很有意思的,感覺比echo更貼近html, 比如說尺寸等數據,寫"20%"和"200px"都可以。echo則盡量封裝的象swing, 屏蔽掉html.
anyway, 對于大多數邏輯都在客戶端的應用,gwt可以大展身手。比如小游戲~
guess number demo看這里:
http://steeven.googlepages.com/MyApp.html
完全在瀏覽器上運行的玩意,沒有寫一句js,感覺還是很爽的~
代碼如下:
package
?org.steeven.gwt.test.client;
import
?com.google.gwt.core.client.EntryPoint;
import
?com.google.gwt.user.client.Random;
import
?com.google.gwt.user.client.ui.Button;
import
?com.google.gwt.user.client.ui.ClickListener;
import
?com.google.gwt.user.client.ui.DialogBox;
import
?com.google.gwt.user.client.ui.Grid;
import
?com.google.gwt.user.client.ui.HasHorizontalAlignment;
import
?com.google.gwt.user.client.ui.RootPanel;
import
?com.google.gwt.user.client.ui.TextBox;
import
?com.google.gwt.user.client.ui.VerticalPanel;
import
?com.google.gwt.user.client.ui.Widget;
/**?*/
/**
?*?
@author
?steeven@gmail.com
?
*/
public
?
class
?MyApp?
implements
?EntryPoint?
{
????TextBox?txtCount?
=
?
new
?TextBox();
????
private
?Grid?pnlMain;
????
private
?Button[]?numbers?
=
?
new
?Button[
100
];
????
private
?
int
?target;
????
private
?
int
?count;
????
private
?DialogBox?box;
????
private
?Button?btnRetry;
????
private
?Button?btnClose;
????
/**?*/
/**
?????*?This?is?the?entry?point?method.
?????
*/
????
public
?
void
?onModuleLoad()?
{
????????VerticalPanel?pnlStatus?
=
?
new
?VerticalPanel();
????????pnlStatus.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
????????pnlStatus.setSpacing(
20
);
????????txtCount.setEnabled(
false
);
????????txtCount.setVisibleLength(
10
);
????????pnlStatus.add(txtCount);
????????btnRetry?
=
?
new
?Button();
????????btnRetry.setHTML(
"
<img?src=\
"
replay.gif\
"
/>?<u>R</u>etry
"
);
????????btnRetry.setAccessKey(
'
r
'
);
????????btnRetry.addClickListener(
new
?ClickListener()?
{
????????????
public
?
void
?onClick(Widget?sender)?
{
????????????????doInit();
????????????}
????????}
);
????????pnlStatus.add(btnRetry);
????????Button?btnAbout?
=
?
new
?Button();
????????btnAbout.setHTML(
"
<img?src='about.gif'/>?<u>A</u>bout
"
);
????????btnAbout.setAccessKey(
'
a
'
);
????????btnAbout.addClickListener(
new
?ClickListener()?
{
????????????
public
?
void
?onClick(Widget?sender)?
{
????????????????doAbout();
????????????}
????????}
);
????????pnlStatus.add(btnAbout);
????????RootPanel.get(
"
status
"
).add(pnlStatus);
????????pnlMain?
=
?
new
?Grid(
10
,?
10
);
????????RootPanel.get(
"
main
"
).add(pnlMain);
????????
for
?(
int
?i?
=
?
0
;?i?
<
?
100
;?i
++
)?
{
????????????numbers[i]?
=
?
new
?Button();
????????????numbers[i].setText(i?
+
?
""
);
????????????numbers[i].addClickListener(
new
?ClickListener()?
{
????????????????
public
?
void
?onClick(Widget?sender)?
{
????????????????????doGuess(sender);
????????????????}
????????????}
);
????????????pnlMain.setWidget(i?
/
?
10
,?i?
%
?
10
,?numbers[i]);
????????}
????????box?
=
?
new
?DialogBox();
????????box.setPopupPosition(
400
,?
200
);
????????btnClose?
=
?
new
?Button(
"
<u>C</u>lose
"
,?
new
?ClickListener()?
{
????????????
public
?
void
?onClick(Widget?sender)?
{
????????????????box.hide();
????????????????doInit();
????????????}
????????}
);
????????btnClose.setAccessKey(
'
c
'
);
????????box.add(btnClose);
????????doInit();
????}
????
protected
?
void
?doGuess(Widget?sender)?
{
????????Button?btn?
=
?(Button)?sender;
????????btnRetry.setEnabled(
true
);
????????
int
?n?
=
?Integer.parseInt(btn.getText());
????????txtCount.setText(
""
?
+
?(
++
count));
????????
if
?(n?
==
?target)?
{
????????????numbers[n].setEnabled(
false
);
????????????btnClose.setFocus(
true
);
????????????box.clear();
????????????box
????????????????????.setHTML(
"
<center><img?src='win.gif'/><h1>YOU?WIN!!!</h1><br/><br/><br/>
"
);
????????????box.add(btnClose);
????????????box.show();
????????}
?
else
?
{
????????????
if
?(n?
<
?target)
????????????????
for
?(
int
?i?
=
?
0
;?i?
<=
?n;?i
++
)
????????????????????numbers[i].setEnabled(
false
);
????????????
else
????????????????
for
?(
int
?i?
=
?n;?i?
<
?
100
;?i
++
)
????????????????????numbers[i].setEnabled(
false
);
????????}
????}
????
protected
?
void
?doAbout()?
{
????????box.clear();
????????box
????????????????.setHTML(
"
<img?src='about.gif'/><h1>Guess?Number</h1><h3>Google?web?toolkit?test</h3>
"
);
????????box.add(btnClose);
????????box.show();
????}
????
private
?
void
?doInit()?
{
????????btnRetry.setEnabled(
false
);
????????target?
=
?Random.nextInt(
99
);
????????count?
=
?
0
;
????????txtCount.setText(
"
0
"
);
????????
for
?(
int
?i?
=
?
0
;?i?
<
?
100
;?i
++
)?
{
????????????numbers[i].setVisible(
true
);
????????????numbers[i].setEnabled(
true
);
????????}
????}
}
第一次玩gwt, 總共花了3個小時,菜呀
發表于 2006-06-02 15:23
steeven
閱讀(1853)
評論(13)
編輯
收藏
所屬分類:
程序點滴
評論
#
re: GWT做的guess number
運氣最好的一次猜中。
最差的是8次,理論上說應該7次就夠了吧?
steeven
評論于 2006-06-02 15:29
回復
更多評論
#
re: GWT做的guess number
可以做個web版的挖地雷,空中接龍,現在不難了 :)
steeven
評論于 2006-06-02 16:07
回復
更多評論
#
re: GWT做的guess number
寫一篇GWT的配置教程吧, 非常期待
QQ
評論于 2006-06-02 16:16
回復
更多評論
#
re: GWT做的guess number
配置很簡單,參照getting started:
http://code.google.com/webtoolkit/gettingstarted.html
1. 建立目錄,進去。md test; cd test. (后面兩個批處理都在當前目錄下干活)
2. 先運行..\projectCreator.cmd創建項目(--help查看幫助)
3. 然后運行..\applicationCreator.cmd
4. 在eclipse里面import, 選擇existing project即可。
host mode debug話要引入那個巨大的jar(最好在eclipse里面建一個變量,以后新建項目比較方便)。引入以后找到com.google.gwt.dev.GWTShell,當普通java類調試即可。
steeven
評論于 2006-06-02 16:30
回復
更多評論
#
re: GWT做的guess number
其實~~~ 其實是因為我在公司, 公司打不開GOOGLE的所有網站, 所以看不到官方教程 -_-!!
QQ
評論于 2006-06-02 16:39
回復
更多評論
#
re: GWT做的guess number
faint
steeven
評論于 2006-06-02 16:44
回復
更多評論
#
re: GWT做的guess number
剛才按你的說法試了一下, 可以運行簡單的例子了, google夠強的
QQ
評論于 2006-06-02 16:54
回復
更多評論
#
re: GWT做的guess number
但是如果想編譯你的例子, 怎么做? 沒有MyApp-compile.cmd, 如果再運行applicationCreator.cmd 是不是會生成新的.JAVA, 把原來的代碼覆蓋了?
QQ
評論于 2006-06-02 16:58
回復
更多評論
#
re: GWT做的guess number
demo頁面右下角有整個項目打包下載。cmd在里面
steeven
評論于 2006-06-02 17:40
回復
更多評論
#
re: GWT做的guess number
需要去SetHTML??蛻舳艘狫ava來寫,感覺真的不是那么爽。。呵呵。
艾塵
評論于 2006-06-02 20:13
回復
更多評論
#
re: GWT做的guess number
setHTML(...)是我偷懶,可以用Image和Label之類的空間完成.
這里可能也是GWK聰明的地方,ECHO里面這些東西一般要用控件組成.GWT則允許HTML的直接存在.控件多了不利于效率的提高.
steeven
評論于 2006-06-04 21:31
回復
更多評論
#
re: GWT做的guess number
http://groups.google.com/group/Google-Web-Toolkit/browse_frm/thread/4d14f7c8ddf4d4d0/6a9b8b50ecb70fc8?q=rpc&rnum=5#6a9b8b50ecb70fc8
gwt現在還沒有rpc的sample, 在group里面找到一個。上次好像有人問過。
steeven
評論于 2006-07-03 13:48
回復
更多評論
#
re: GWT做的guess number
運行你這個程序出現下面2個錯誤,怎么回事???
[ERROR] Unable to load module entry point class com.sample.guess.client.GuessNum
java.lang.NullPointerException: null
at com.sample.guess.client.GuessNum.onModuleLoad(GuessNum.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:138)
[ERROR] Failure to load module 'com.sample.guess.GuessNum'
yanghuixia
評論于 2006-12-28 21:43
回復
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
吹一吹偶的新作品:skype remote desktop
GWT開發中的幾個問題
開發過程中的雞生蛋蛋生雞的問題
監聽Swing窗口的鍵盤鼠標事件
GWT做的guess number
EMF之ResourceSet探索(4)
EMF之ResourceSet探索(3)
EMF之ResourceSet探索(2)
EMF之ResourceSet探索(1)
Annotation Wizard for EMF插件
CALENDER
<
2006年6月
>
日
一
二
三
四
五
六
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(10)
給我留言
查看公開留言
查看私人留言
隨筆分類
學習筆記(11)
(rss)
程序點滴(16)
(rss)
胡思亂想(8)
(rss)
隨筆檔案
2009年5月 (1)
2006年12月 (1)
2006年7月 (2)
2006年6月 (7)
2006年5月 (8)
2006年4月 (2)
2006年3月 (1)
2006年1月 (2)
2005年12月 (1)
文章檔案
2006年8月 (1)
相冊
annotation_wizard
samples
我的鏈接
我在csdn上的窩
(rss)
很久沒打理了
我在MSN上的窩
(rss)
我在博客園的窩
(rss)
我在天涯上的窩
搜索
最新評論
1.?re: 編程使用SDO[EMF兄弟篇]
最近也在看這個,有沒有好點的文章和代碼啊,有的話麻煩給些,謝謝,郵箱:
huanggenping2002@163.com
--zebrahgp
2.?re: SNMP親密接觸
請問,我在接收Trap時,同時有多個設備發送,在同一時間接收到的會有丟失的情況,怎么解決呢?snmp4j自帶的ThreadPool類有沒有在這方面起到多線程作用?
--analyser
3.?re: 編程使用SDO[EMF兄弟篇]
我也在研究soa,如果你有sdo方面的代碼,麻煩您給我一份作為參考,謝謝
郵箱: litao5168@sohu.com 謝謝
--litao
4.?re: 編程使用SDO[EMF兄弟篇]
我也在研究soa,如果你有sdo方面的代碼,麻煩您給我一份作為參考,謝謝
--litao
5.?re: 編程使用SDO[EMF兄弟篇]
評論內容較長,點擊標題查看
--1984prince
Powered By:
博客園
模板提供
:
滬江博客
主站蜘蛛池模板:
棋牌
|
黄龙县
|
灵宝市
|
寻甸
|
万山特区
|
安庆市
|
富平县
|
哈尔滨市
|
嵊州市
|
西昌市
|
武清区
|
北辰区
|
搜索
|
巫溪县
|
炎陵县
|
台湾省
|
宿松县
|
闽清县
|
枣庄市
|
临城县
|
江源县
|
洛阳市
|
上蔡县
|
通城县
|
邵东县
|
三明市
|
平安县
|
宜城市
|
兴和县
|
景泰县
|
墨竹工卡县
|
安平县
|
眉山市
|
宁海县
|
台东县
|
如东县
|
开封市
|
康定县
|
佛坪县
|
施甸县
|
贵州省
|