随笔:24 文章:1 评论:66 引用:0
steeven
BlogJava
首页
发新随笔
发新文章
联系
聚合
管理
2006年6月2日
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个小时,菜呀
posted @
2006-06-02 15:23
steeven 阅读(1458) |
评论 (13)
|
编辑
收藏
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
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(7)
给我留言
查看公开留言
查看私人留言
随笔分类
学习笔记(11)
(rss)
程序点滴(16)
(rss)
胡思乱想(8)
(rss)
随笔档案
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方面的代码,麻烦您给我一份作为参考,谢谢
--litao
4. re: 编程使用SDO[EMF兄弟篇]
我也在研究soa,如果你有sdo方面的代码,麻烦您给我一份作为参考,谢谢
邮箱: litao5168@sohu.com 谢谢
--litao
5. re: 编程使用SDO[EMF兄弟篇]
评论内容较长,点击标题查看
--1984prince
Powered By:
博客园
模板提供
:
沪江博客