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. 2014年度辛星html教程夏季版第四节

    我们前面也涉及了HTML中的一些东西,接下来我们要涉及到图像了,如果没有图像,即使文字的样式再多,再复杂,终归还是单调的,我们就需要用图片来给我们的网页增加更多的表现形式. ************* ...

  2. 基于u-boot源码的简单shell软件实现

    一.概述 1.shell概念 Shell(命令解析器),它用于接收用户输入的命令,进行解析,然后调用相应的应用程序,为使用者提供了使用软件的界面. shell是操作系统最外面的一层.shell管理你与 ...

  3. 破解EXCEL2007的密码

    破解EXCEL2007的密码 xshzhao (斑竹)顶楼举报 我有一个EXCEL2007文件(后缀是XLSX),由于设置了打开密码.现在密码搞忘了,这个文件对我很重要. 我试过了Office Pas ...

  4. Unreal Engine4 蓝图入门

    微信公众号:UE交流学习    UE4开发群:344602753 蓝图是Unreal Engine的特点,用C++编程固然好,但是效率要低很多,主要是国内资料比较少,所以不太容易学习,用蓝图编程可以节 ...

  5. ASP.NET多用户操作相同互斥的对象

    [一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/p/3574154.html ] 现象:公有静态变量不可用于ASP.NET多用户操作,否则该变量会被多 ...

  6. Multi-Die系统介绍

    一个典型的存储系统一般是有几片NAND存储器组成的.一般会使用8-bit的总线,用来将不同的存储器与控制器进行连接,如图2.32所示.一个系统中多片NAND的存储系统可以提高存储容量,同时还可以提高读 ...

  7. 查找mysql数据文件存放路径

    show variables like 'datadir%'; show variables当前的会话,是系统参数 是静态 show global variables全局 show status是系统 ...

  8. javascript外部使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. bzoj1878

    像我这种蒟蒻这道题从在线算法思考基本毫无思路 但是发现题目中只涉及到询问而不涉及到修改,这类题目一般都是离线算法大概 考虑到这题为什么不能直接区间求值,因为区间中同色点会被重复计算(废话) 下面我们就 ...

  10. js 弹出页面传值

    有页面a和页面b,页面a中有一个文本框和一个按钮,点按钮弹出页面b,页面b也有一个文本框,在文本框中输入值,在不经过后台用js实现把页面b的文本框的值传到页面a,赋给页面a的文本框 a页面代码< ...