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. about hadoop-eclipse-plugin used by IDE

    Apache Hadoop Development Tools (HDT) is still in development phase. So, no official distribution of ...

  2. JDOM

    JDOM是什么: To provide a complete, Java-based solution for accessing, manipulating, and outputting XML ...

  3. ubuntu系统下创建软件桌面快捷方式

    转自ubuntu系统下创建软件桌面快捷方式 默认情况下,ubuntu会将自动安装的软件快捷方式保存在/usr/share/applications目录下,如果我们要创建桌面快捷方式,只需要右键-复制- ...

  4. 【UVA 11383】 Golden Tiger Claw (KM算法副产物)

    Omi, Raymondo, Clay and Kimiko are on new adventure- in search of new Shen Gong Wu. But EvilBoy Geni ...

  5. 配置Tomcat JNDI数据源

    原文地址:http://my.oschina.net/xiaomaoandhong/blog/74584 先记录在此,按照博文未配置成功

  6. [wikioi]没有上司的舞会

    树形DP.用F[k][0]和F[k][1]表示某节点不选和选了之后子树的最大值.那么:f[i][0]=sigma(max(f[k][0],f[k][1]))f[i][1]=sigma(f[k][0]) ...

  7. 【简译】jQuery对象的奥秘:基础介绍

    本文翻译自此文章 你有没有遇到过类似$(".cta").click(function(){})这样的JavaScript代码并且在想“$('#x')是什么”?如果这些对你想天书一样 ...

  8. android视频播放

    视频播放我们用到的是MediaPlayer,显示控件使用的surfaceView 我们向SD卡中先添加个视频文件,我的是xajh.3gp,不要用mp4,MP4会出现 should have subti ...

  9. Linux中的随机数文件 /dev/random /dev/urandom

    Linux中的随机数可以从两个特殊的文件中产生,一个是/dev/urandom.另外一个是/dev/random.他们产生随机数的原理是利用当前系统的熵池来计算出固定一定数量的随机比特,然后将这些比特 ...

  10. 开始hadoop

    hadoop介绍 分布式存储系统HDFS(Hadoop Distributed File System),提供了高可靠性.高扩展性和高吞吐率的数据存储服务: 资源管理系统YARN(Yet Anothe ...