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. OC中格式化输出符号

    定义 说明 %@ Objective-C object, printed as the string returned by descriptionWithLocale: if available, ...

  2. 定位 - CoreLocation - 区域报警

    #import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewCont ...

  3. 引用Excel时 未在本地计算机上注册ace.oledb.12.0

    可能由于未安装数据库补丁 下载地址http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c-4e19-b0da-1463960fdcdb/A ...

  4. c/c++ 传统数组的缺点

    专题:  动态内存分配 (所有高级语言,没有C里深刻) 传统数组的缺点: 1.数组长度必须事先指定,而且只能是常整数,不能是变量     例子 ]; //必须事先指定,而且只能是常整数 ; int a ...

  5. 分享七款视差滚动效果的jQuery 插件

    视差(Parallax)是指从不同的点看一个物体时形成的视觉差异,这个名词是源自希腊文的παράλλαξις (parallaxis),意思是”改变”.在网页设计中,视差滚动(Parallax Scr ...

  6. Codeforces Round #198 (Div. 2) —— C

    C题很容易看懂题目,不过两个循环肯定会TLE,所以得用点小聪明: 首先排好序,因为是全排列,乱序和顺序的结果是一样的: 然后呢···· 如果是数列 1 2 3 4 5 元素1 被 2 3 4 5每个减 ...

  7. ThinkPHP3.1快速入门(3)查询语言

    http://www.thinkphp.cn/info/115.html 介绍 ThinkPHP内置了非常灵活的查询方法,可以快速的进行数据查询操作,查询条件可以用于读取.更新和删除等操作,主要涉及到 ...

  8. 配置PhpStorm调试PHP

    配置PhpStorm调试PHP 第一步:配置 XDebug 下载安装XDebug到本地环境(参考:Zend Studio 9.x + xampp + XDebug 调试环境安装详解),打开php.in ...

  9. Jar包可执行??

    第一次听说,jvm加载包,必须rwx么?

  10. 李洪强漫谈iOS开发[C语言-028]-逗号表达式