隨筆:25 文章:1 評論:66 引用:0
steeven
BlogJava
首頁
發(fā)新隨筆
發(fā)新文章
聯(lián)系
聚合
管理
GWT做的guess number
gwt的這些特性還是很有意思的,感覺比echo更貼近html, 比如說尺寸等數(shù)據(jù),寫"20%"和"200px"都可以。echo則盡量封裝的象swing, 屏蔽掉html.
anyway, 對于大多數(shù)邏輯都在客戶端的應(yīng)用,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個小時,菜呀
發(fā)表于 2006-06-02 15:23
steeven
閱讀(1847)
評論(13)
編輯
收藏
所屬分類:
程序點滴
評論
#
re: GWT做的guess number
運氣最好的一次猜中。
最差的是8次,理論上說應(yīng)該7次就夠了吧?
steeven
評論于 2006-06-02 15:29
回復(fù)
更多評論
#
re: GWT做的guess number
可以做個web版的挖地雷,空中接龍,現(xiàn)在不難了 :)
steeven
評論于 2006-06-02 16:07
回復(fù)
更多評論
#
re: GWT做的guess number
寫一篇GWT的配置教程吧, 非常期待
QQ
評論于 2006-06-02 16:16
回復(fù)
更多評論
#
re: GWT做的guess number
配置很簡單,參照getting started:
http://code.google.com/webtoolkit/gettingstarted.html
1. 建立目錄,進去。md test; cd test. (后面兩個批處理都在當(dāng)前目錄下干活)
2. 先運行..\projectCreator.cmd創(chuàng)建項目(--help查看幫助)
3. 然后運行..\applicationCreator.cmd
4. 在eclipse里面import, 選擇existing project即可。
host mode debug話要引入那個巨大的jar(最好在eclipse里面建一個變量,以后新建項目比較方便)。引入以后找到com.google.gwt.dev.GWTShell,當(dāng)普通java類調(diào)試即可。
steeven
評論于 2006-06-02 16:30
回復(fù)
更多評論
#
re: GWT做的guess number
其實~~~ 其實是因為我在公司, 公司打不開GOOGLE的所有網(wǎng)站, 所以看不到官方教程 -_-!!
QQ
評論于 2006-06-02 16:39
回復(fù)
更多評論
#
re: GWT做的guess number
faint
steeven
評論于 2006-06-02 16:44
回復(fù)
更多評論
#
re: GWT做的guess number
剛才按你的說法試了一下, 可以運行簡單的例子了, google夠強的
QQ
評論于 2006-06-02 16:54
回復(fù)
更多評論
#
re: GWT做的guess number
但是如果想編譯你的例子, 怎么做? 沒有MyApp-compile.cmd, 如果再運行applicationCreator.cmd 是不是會生成新的.JAVA, 把原來的代碼覆蓋了?
QQ
評論于 2006-06-02 16:58
回復(fù)
更多評論
#
re: GWT做的guess number
demo頁面右下角有整個項目打包下載。cmd在里面
steeven
評論于 2006-06-02 17:40
回復(fù)
更多評論
#
re: GWT做的guess number
需要去SetHTML??蛻舳艘狫ava來寫,感覺真的不是那么爽。。呵呵。
艾塵
評論于 2006-06-02 20:13
回復(fù)
更多評論
#
re: GWT做的guess number
setHTML(...)是我偷懶,可以用Image和Label之類的空間完成.
這里可能也是GWK聰明的地方,ECHO里面這些東西一般要用控件組成.GWT則允許HTML的直接存在.控件多了不利于效率的提高.
steeven
評論于 2006-06-04 21:31
回復(fù)
更多評論
#
re: GWT做的guess number
http://groups.google.com/group/Google-Web-Toolkit/browse_frm/thread/4d14f7c8ddf4d4d0/6a9b8b50ecb70fc8?q=rpc&rnum=5#6a9b8b50ecb70fc8
gwt現(xiàn)在還沒有rpc的sample, 在group里面找到一個。上次好像有人問過。
steeven
評論于 2006-07-03 13:48
回復(fù)
更多評論
#
re: GWT做的guess number
運行你這個程序出現(xiàn)下面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
回復(fù)
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
吹一吹偶的新作品:skype remote desktop
GWT開發(fā)中的幾個問題
開發(fā)過程中的雞生蛋蛋生雞的問題
監(jiān)聽Swing窗口的鍵盤鼠標(biāo)事件
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)
給我留言
查看公開留言
查看私人留言
隨筆分類
學(xué)習(xí)筆記(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時,同時有多個設(shè)備發(fā)送,在同一時間接收到的會有丟失的情況,怎么解決呢?snmp4j自帶的ThreadPool類有沒有在這方面起到多線程作用?
--analyser
3.?re: 編程使用SDO[EMF兄弟篇]
我也在研究soa,如果你有sdo方面的代碼,麻煩您給我一份作為參考,謝謝
郵箱: litao5168@sohu.com 謝謝
--litao
4.?re: 編程使用SDO[EMF兄弟篇]
我也在研究soa,如果你有sdo方面的代碼,麻煩您給我一份作為參考,謝謝
--litao
5.?re: 編程使用SDO[EMF兄弟篇]
評論內(nèi)容較長,點擊標(biāo)題查看
--1984prince
Powered By:
博客園
模板提供
:
滬江博客
主站蜘蛛池模板:
黄色免费在线观看网址
|
国产在线观看免费视频播放器
|
久久综合亚洲色hezyo
|
亚洲精品在线网站
|
亚洲精品无码久久千人斩
|
在线免费观看a级片
|
嫖丰满老熟妇AAAA片免费看
|
久久精品成人免费看
|
人妻仑乱A级毛片免费看
|
亚洲欧美日韩中文字幕在线一区
|
91亚洲自偷手机在线观看
|
日本亚洲成高清一区二区三区
|
亚洲Aⅴ无码一区二区二三区软件
|
成人免费淫片在线费观看
|
91免费精品国自产拍在线不卡
|
亚欧免费一级毛片
|
97无码人妻福利免费公开在线视频
|
精品在线免费视频
|
亚洲av永久中文无码精品综合
|
亚洲精品国产综合久久久久紧
|
亚洲高清美女一区二区三区
|
国产成人精品日本亚洲网站
|
WWW亚洲色大成网络.COM
|
日韩亚洲产在线观看
|
一本色道久久88亚洲精品综合
|
久草视频在线免费
|
h视频在线免费看
|
57pao一国产成永久免费
|
最近2019中文字幕免费直播
|
无码中文字幕av免费放dvd
|
日本免费污片中国特一级
|
久久狠狠躁免费观看2020
|
久久久久成人片免费观看蜜芽
|
亚洲国产精品免费视频
|
亚洲国产二区三区久久
|
色噜噜综合亚洲av中文无码
|
91亚洲国产成人久久精品网站
|
亚洲综合激情另类小说区
|
亚洲国产精品白丝在线观看
|
亚洲成aⅴ人片在线观
|
亚洲高清视频在线
|