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. sql join 用法

    SQL JOIN 的用法   关于sql语句中的连接(join)关键字,是较为常用而又不太容易理解的关键字,下面这个例子给出了一个简单的解释 --建表table1,table2:create tabl ...

  2. ARM编译器4字节对齐

    (1)我们假设只有一个赋初值的char型全局变量,那么系统会在data区分配一个4字节的存储空间来存储它.实际上,只用了1个字节,但是为了4字节对齐,只好分配4个字节,所以就会有3个字节浪费. (2) ...

  3. Android中通过访问本地相册或者相机设置用户头像

    目前几乎所有的APP在用户注册时都会有设置头像的需求,大致分为三种情况: (1)通过获取本地相册的图片,经过裁剪后作为头像. (2)通过启动手机相机,现拍图片然后裁剪作为头像. (3)在APP中添加一 ...

  4. Swift -- SnapKit

    Snapkit SnapKit是专门为Swift语言提供AutoLayout布局使用的,特点为语法简洁易用. let subview = UIView() subview.backgroundColo ...

  5. App 性能分析

    关键因素: ---- Instrument 性能分析神器 1. 启动时间 应用启动时间长短对用户第一次体验至关重要,同时系统对应用的启动.恢复等状态的运行时间也有严格的要求,在应用超时的情况下系统会直 ...

  6. 一个Bootstrap风格的分页控件

      http://www.cnblogs.com/wangwei123/p/3682626.html 主题 jQueryBootstrap 一个Bootstrap风格的分页控件,对于喜欢Bootstr ...

  7. jquery多级手风琴插件–accordion.js

    手风琴菜单一般用于下拉导航,由于外观非常简洁,使用起来跟手风琴一样可以拉伸和收缩而得名,项目中适当应用手风琴效果会给用户带来非常好的体验.本文借助jQuery插件轻松打造一个非常不错的手风琴效果的菜单 ...

  8. 【HDU 4436】 str2int (广义SAM)

    str2int Problem Description In this problem, you are given several strings that contain only digits ...

  9. bzoj1093

    首先缩点然后半连通其实就是缩点后节点数最多的链注意这里一定是一条链才一定是半连通然后重建图拓扑排序上做dp即可 type node=record po,next:longint; end; ..] o ...

  10. BZOJ_1901_&_ZJU_2112_Dynamic_Rankings_(主席树+树状数组/线段树+(Treap/Splay))

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1901 给出一个长度为n的数列A,有m次询问,询问分两种:1.修改某一位置的值;2.求区间[l, ...