1. package com.zly.client;
  2. import com.google.gwt.core.client.EntryPoint;
  3. import com.google.gwt.event.dom.client.BlurEvent;
  4. import com.google.gwt.event.dom.client.BlurHandler;
  5. import com.google.gwt.event.dom.client.ChangeEvent;
  6. import com.google.gwt.event.dom.client.ChangeHandler;
  7. import com.google.gwt.event.dom.client.ClickEvent;
  8. import com.google.gwt.event.dom.client.ClickHandler;
  9. import com.google.gwt.event.dom.client.DomEvent;
  10. import com.google.gwt.event.dom.client.ErrorEvent;
  11. import com.google.gwt.event.dom.client.ErrorHandler;
  12. import com.google.gwt.event.dom.client.FocusEvent;
  13. import com.google.gwt.event.dom.client.FocusHandler;
  14. import com.google.gwt.event.dom.client.KeyDownEvent;
  15. import com.google.gwt.event.dom.client.KeyDownHandler;
  16. import com.google.gwt.event.dom.client.KeyPressEvent;
  17. import com.google.gwt.event.dom.client.KeyPressHandler;
  18. import com.google.gwt.event.dom.client.KeyUpEvent;
  19. import com.google.gwt.event.dom.client.KeyUpHandler;
  20. import com.google.gwt.event.dom.client.LoadEvent;
  21. import com.google.gwt.event.dom.client.LoadHandler;
  22. import com.google.gwt.event.dom.client.MouseMoveEvent;
  23. import com.google.gwt.event.dom.client.MouseMoveHandler;
  24. import com.google.gwt.event.dom.client.MouseOutEvent;
  25. import com.google.gwt.event.dom.client.MouseOutHandler;
  26. import com.google.gwt.event.dom.client.MouseOverEvent;
  27. import com.google.gwt.event.dom.client.MouseOverHandler;
  28. import com.google.gwt.event.dom.client.MouseUpEvent;
  29. import com.google.gwt.event.dom.client.MouseUpHandler;
  30. import com.google.gwt.event.dom.client.MouseWheelEvent;
  31. import com.google.gwt.event.dom.client.MouseWheelHandler;
  32. import com.google.gwt.event.dom.client.ScrollEvent;
  33. import com.google.gwt.event.dom.client.ScrollHandler;
  34. import com.google.gwt.user.client.DOM;
  35. import com.google.gwt.user.client.Window;
  36. import com.google.gwt.user.client.ui.Button;
  37. import com.google.gwt.user.client.ui.Grid;
  38. import com.google.gwt.user.client.ui.HTML;
  39. import com.google.gwt.user.client.ui.Image;
  40. import com.google.gwt.user.client.ui.Label;
  41. import com.google.gwt.user.client.ui.RootPanel;
  42. import com.google.gwt.user.client.ui.ScrollPanel;
  43. import com.google.gwt.user.client.ui.SourcesTableEvents;
  44. import com.google.gwt.user.client.ui.TableListener;
  45. import com.google.gwt.user.client.ui.TextArea;
  46. import com.google.gwt.user.client.ui.TextBox;
  47. import com.google.gwt.user.client.ui.Tree;
  48. import com.google.gwt.user.client.ui.TreeItem;
  49. import com.google.gwt.user.client.ui.TreeListener;
  50. import com.google.gwt.user.client.ui.Widget;
  51. public class Test implements EntryPoint {
  52. @SuppressWarnings("deprecation")
  53. public void onModuleLoad() {
  54. Label label = new Label("Change event example:");
  55. add(label);
  56. final TextBox box = new TextBox();
  57. RootPanel.get().add(box);
  58. box.addChangeHandler(new ChangeHandler() {
  59. public void onChange(ChangeEvent event) {
  60. alert("change event occur");
  61. }
  62. });
  63. Label label2 = new Label("Click event example");
  64. add(label2);
  65. final Button[] btns = new Button[5];
  66. for (int i = 0; i < btns.length; i++) {
  67. btns[i] = new Button("Button" + i);
  68. add(btns[i]);
  69. final Button btn = btns[i];
  70. btns[i].addClickHandler(new ClickHandler() {
  71. public void onClick(ClickEvent event) {
  72. alert(btn.getText() + " " + " click event occur");
  73. }
  74. });
  75. }
  76. Label label3 = new Label("Focus event example");
  77. add(label3);
  78. final TextBox box2 = new TextBox();
  79. add(box2);
  80. box2.addFocusHandler(new FocusHandler() {
  81. public void onFocus(FocusEvent event) {
  82. box2.setText("got focus!");
  83. }
  84. });
  85. box2.addBlurHandler(new BlurHandler() {
  86. public void onBlur(BlurEvent event) {
  87. box2.setText("lost focus!");
  88. }
  89. });
  90. Label label4 = new Label("keyboard event example");
  91. add(label4);
  92. TextBox box3 = new TextBox();
  93. add(box3);
  94. box3.addKeyDownHandler(new KeyDownHandler() {
  95. public void onKeyDown(KeyDownEvent event) {
  96. alert("you press " + (char)event.getNativeKeyCode() + " down");
  97. }
  98. });
  99. box3.addKeyPressHandler(new KeyPressHandler() {
  100. public void onKeyPress(KeyPressEvent event) {
  101. alert("you press " + event.getCharCode());
  102. }
  103. });
  104. box3.addKeyUpHandler(new KeyUpHandler() {
  105. public void onKeyUp(KeyUpEvent event) {
  106. alert("you press " + (char)event.getNativeKeyCode() + " up");
  107. }
  108. });
  109. Label label5 = new Label("Image event example");
  110. add(label5);
  111. final Image image = new Image("xx.jpg");
  112. add(image);
  113. image.addLoadHandler(new LoadHandler() {
  114. public void onLoad(LoadEvent event) {
  115. }
  116. });
  117. image.addErrorHandler(new ErrorHandler() {
  118. public void onError(ErrorEvent event) {
  119. image.setTitle("no such image");
  120. }
  121. });
  122. HTML html = new HTML("<div></div>");
  123. html.setSize("300", "300");
  124. DOM.setStyleAttribute(html.getElement(), "border", "solid 1px");
  125. add(html);
  126. html.addMouseOverHandler(new MouseOverHandler() {
  127. public void onMouseOver(MouseOverEvent event) {
  128. alert("mouse over");
  129. }
  130. });
  131. html.addMouseMoveHandler(new MouseMoveHandler() {
  132. public void onMouseMove(MouseMoveEvent event) {
  133. alert(event.getClientX() + ":" + event.getClientY());
  134. }
  135. });
  136. html.addMouseOutHandler(new MouseOutHandler() {
  137. public void onMouseOut(MouseOutEvent event) {
  138. alert("mouse out");
  139. }
  140. });
  141. html.addMouseUpHandler(new MouseUpHandler() {
  142. public void onMouseUp(MouseUpEvent event) {
  143. alert("mouse up");
  144. }
  145. });
  146. ScrollPanel panel  = new ScrollPanel();
  147. panel.setSize("100", "30");
  148. panel.add(new Label("This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label."));
  149. add(panel);
  150. panel.addScrollHandler(new ScrollHandler() {
  151. public void onScroll(ScrollEvent event) {
  152. box.setText("Scorll!!!");
  153. }
  154. });
  155. TextArea area = new TextArea();
  156. area.setSize("150", "150");
  157. area.setValue("This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.");
  158. area.addMouseWheelHandler(new MouseWheelHandler() {
  159. public void onMouseWheel(MouseWheelEvent event) {
  160. alert("mouse wheel occur!");
  161. }
  162. });
  163. add(area);
  164. final Grid grid = new Grid(3 , 3);
  165. for (int i = 0; i < 3; i++) {
  166. for (int j = 0; j < 3; j++) {
  167. grid.setText(i, j, "Cell(" + i + " , " + j + ")");
  168. }
  169. }
  170. grid.setBorderWidth(1);
  171. add(grid);
  172. grid.addTableListener(new TableListener() {
  173. public void onCellClicked(SourcesTableEvents sender, int row,
  174. int cell) {
  175. DOM.setStyleAttribute(((Grid)(sender)).getCellFormatter().getElement(row, cell), "border", "3px solid #f00");
  176. }
  177. });
  178. Tree tree = new Tree();
  179. tree.addItem("Item1");
  180. tree.addItem("Item2");
  181. tree.addItem("Item3");
  182. tree.addItem("Item4");
  183. tree.addTreeListener(new TreeListener() {
  184. public void onTreeItemSelected(TreeItem item) {
  185. alert(item.getText() + " selected");
  186. }
  187. public void onTreeItemStateChanged(TreeItem item) {
  188. alert(item.getText() + " changed");
  189. }
  190. });
  191. add(tree);
  192. }
  193. public void add(Widget element) {
  194. RootPanel.get().add(element);
  195. }
  196. public void alert(String src) {
  197. Window.alert(src);
  198. }
  199. public String getEventType(DomEvent<?> event) {
  200. return event.toString();
  201. }
  202. }

GWT事件处理的更多相关文章

  1. GWT资料收集

    1.别人的GWT笔记 http://www.blogjava.net/peacess/archive/2007/08/06/84950.html 2.GWT系统类库参考手册 http://www.bo ...

  2. JavaScript权威设计--事件处理介绍(简要学习笔记十七)

    1.事件相关概念 事件类型:一个用来说明发生什么类型事件的字符串 事件目标:是发生的事件或与之相关的对象. 事件处理程序(事件监听程序):是处理货响应事件的函数. 事件对象:是与特定事件相关并且包含有 ...

  3. JavaScript移除绑定在元素上的匿名事件处理函数

    前言: 面试的时候有点蒙,结束之后想想自己好像根本就误解了面试官的问题,因为我理解的这个问题本身就没有意义.但是当时已经有一些思路,但是在一个点上被卡住. 结束之后脑子瞬间灵光,想出了当时没有迈出的那 ...

  4. linux输入子系统(input subsystem)之evdev.c事件处理过程

    1.代码 input_subsys.drv.c 在linux输入子系统(input subsystem)之按键输入和LED控制的基础上有小改动,input_subsys_test.c不变. input ...

  5. 【repost】JavaScript 事件模型 事件处理机制

    什么是事件? 事件(Event)是JavaScript应用跳动的心脏 ,也是把所有东西粘在一起的胶水.当我们与浏览器中 Web 页面进行某些类型的交互时,事件就发生了.事件可能是用户在某些内容上的点击 ...

  6. 【原】iOS学习之事件处理的原理

    在iOS学习23之事件处理中,小编详细的介绍了事件处理,在这里小编叙述一下它的相关原理 1.UITouch对象 在触摸事件的处理方法中都会有一个存放着UITouch对象的集合,这个参数有什么用呢? ( ...

  7. android事件处理之基于监听

    Android提供了了两种事件处理方式:基于回调和基于监听. 基于监听: 监听涉及事件源,事件,事件监听器.用注册监听器的方法将某个监听器注册到事件源上,就可以对发生在事件源上的时间进行监听. 最简单 ...

  8. Nova PhoneGap框架 第七章 设备事件处理

    我们的框架包含了几种设备事件的处理,目的是为了让我们的程序员更容易的完成代码.这些事件包括:回退键(Android)和横竖屏切换事件. 7.1 Android回退键 首先来说说回退键的事件处理.当用户 ...

  9. 译:DOM2中的高级事件处理(转)

    17.2. DOM2中的高级事件处理(Advanced Event Handling with DOM Level 2)        译自:JavaScript: The Definitive Gu ...

随机推荐

  1. Poco库之XML操作

    平台ubuntu14.04LTS     Poco版本:Poco1.6.1 #include <Poco/DOM/Text.h>#include <Poco/DOM/Element. ...

  2. C#数据类型-string

    string是各种编程语言中最基础的数据类型,长期以来受尽其它类的压迫,经常被肢解(Substring.Split).蹂躏(Join)... 而现在C#数据类型string要“翻身闹革命”了,它几乎无 ...

  3. myeclipse启动项目时报:An internal error occurred during: "Launching TestSpring on Tomcat 7.x". java.lang.NullPointerException 解决方法

    如果出现了上述的错误按照如下的3个步骤解决: 1.首先关闭MyEclipse工作空间. 2.然后删除工作空间下的 “/.metadata/.plugins/org.eclipse.core.runti ...

  4. 第 16 章 观察者模式【Observer Pattern】

    以下内容出自:<<24种设计模式介绍与6大设计原则>> <孙子兵法>有云:“知彼知己,百战不殆:不知彼而知己,一胜一负:不知彼,不知己,每战必殆”,那怎么才能知己知 ...

  5. webserver<2>

    #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wai ...

  6. bzoj 3328: PYXFIB 数论

    3328: PYXFIB Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 130  Solved: 41[Submit][Status][Discuss ...

  7. 【技术贴】Maven打包文件增加时间后缀

    构建war包,或者jar包的,时候,maven会自动增加一个版本号和时间放在jar包后面比如poi-3.9-20131115.jar这样子,但是我自己打war包,总是给我生成一个快照的后缀report ...

  8. hdu 4445

    今天模拟了一场去年金华的现场赛: 我和小珺两人出了5个题,感觉还可以: 不过这次的题目确实比较简单: 这个题目感觉不错,不难,以前见过用这种方法的,但一直没写过: 这次写下练练手: 思路,将角度分成1 ...

  9. IEEE二进制浮点数算术标准(IEEE 754)

    整理自IEEE 754 IEEE二进制浮点数算术标准(IEEE 754)是20世纪80年代以来最广泛使用的浮点数运算标准,为许多CPU与浮点运算器所采用.这个标准定义了表示浮点数的格式(包括负零-0) ...

  10. http://jinnianshilongnian.iteye.com/blog/1996071

    http://jinnianshilongnian.iteye.com/blog/1996071 http://my.oschina.net/jkcui/blog/388400 http://tian ...