GWT事件处理
- package com.zly.client;
- import com.google.gwt.core.client.EntryPoint;
- import com.google.gwt.event.dom.client.BlurEvent;
- import com.google.gwt.event.dom.client.BlurHandler;
- import com.google.gwt.event.dom.client.ChangeEvent;
- import com.google.gwt.event.dom.client.ChangeHandler;
- import com.google.gwt.event.dom.client.ClickEvent;
- import com.google.gwt.event.dom.client.ClickHandler;
- import com.google.gwt.event.dom.client.DomEvent;
- import com.google.gwt.event.dom.client.ErrorEvent;
- import com.google.gwt.event.dom.client.ErrorHandler;
- import com.google.gwt.event.dom.client.FocusEvent;
- import com.google.gwt.event.dom.client.FocusHandler;
- import com.google.gwt.event.dom.client.KeyDownEvent;
- import com.google.gwt.event.dom.client.KeyDownHandler;
- import com.google.gwt.event.dom.client.KeyPressEvent;
- import com.google.gwt.event.dom.client.KeyPressHandler;
- import com.google.gwt.event.dom.client.KeyUpEvent;
- import com.google.gwt.event.dom.client.KeyUpHandler;
- import com.google.gwt.event.dom.client.LoadEvent;
- import com.google.gwt.event.dom.client.LoadHandler;
- import com.google.gwt.event.dom.client.MouseMoveEvent;
- import com.google.gwt.event.dom.client.MouseMoveHandler;
- import com.google.gwt.event.dom.client.MouseOutEvent;
- import com.google.gwt.event.dom.client.MouseOutHandler;
- import com.google.gwt.event.dom.client.MouseOverEvent;
- import com.google.gwt.event.dom.client.MouseOverHandler;
- import com.google.gwt.event.dom.client.MouseUpEvent;
- import com.google.gwt.event.dom.client.MouseUpHandler;
- import com.google.gwt.event.dom.client.MouseWheelEvent;
- import com.google.gwt.event.dom.client.MouseWheelHandler;
- import com.google.gwt.event.dom.client.ScrollEvent;
- import com.google.gwt.event.dom.client.ScrollHandler;
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.Window;
- import com.google.gwt.user.client.ui.Button;
- import com.google.gwt.user.client.ui.Grid;
- import com.google.gwt.user.client.ui.HTML;
- import com.google.gwt.user.client.ui.Image;
- import com.google.gwt.user.client.ui.Label;
- import com.google.gwt.user.client.ui.RootPanel;
- import com.google.gwt.user.client.ui.ScrollPanel;
- import com.google.gwt.user.client.ui.SourcesTableEvents;
- import com.google.gwt.user.client.ui.TableListener;
- import com.google.gwt.user.client.ui.TextArea;
- import com.google.gwt.user.client.ui.TextBox;
- import com.google.gwt.user.client.ui.Tree;
- import com.google.gwt.user.client.ui.TreeItem;
- import com.google.gwt.user.client.ui.TreeListener;
- import com.google.gwt.user.client.ui.Widget;
- public class Test implements EntryPoint {
- @SuppressWarnings("deprecation")
- public void onModuleLoad() {
- Label label = new Label("Change event example:");
- add(label);
- final TextBox box = new TextBox();
- RootPanel.get().add(box);
- box.addChangeHandler(new ChangeHandler() {
- public void onChange(ChangeEvent event) {
- alert("change event occur");
- }
- });
- Label label2 = new Label("Click event example");
- add(label2);
- final Button[] btns = new Button[5];
- for (int i = 0; i < btns.length; i++) {
- btns[i] = new Button("Button" + i);
- add(btns[i]);
- final Button btn = btns[i];
- btns[i].addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent event) {
- alert(btn.getText() + " " + " click event occur");
- }
- });
- }
- Label label3 = new Label("Focus event example");
- add(label3);
- final TextBox box2 = new TextBox();
- add(box2);
- box2.addFocusHandler(new FocusHandler() {
- public void onFocus(FocusEvent event) {
- box2.setText("got focus!");
- }
- });
- box2.addBlurHandler(new BlurHandler() {
- public void onBlur(BlurEvent event) {
- box2.setText("lost focus!");
- }
- });
- Label label4 = new Label("keyboard event example");
- add(label4);
- TextBox box3 = new TextBox();
- add(box3);
- box3.addKeyDownHandler(new KeyDownHandler() {
- public void onKeyDown(KeyDownEvent event) {
- alert("you press " + (char)event.getNativeKeyCode() + " down");
- }
- });
- box3.addKeyPressHandler(new KeyPressHandler() {
- public void onKeyPress(KeyPressEvent event) {
- alert("you press " + event.getCharCode());
- }
- });
- box3.addKeyUpHandler(new KeyUpHandler() {
- public void onKeyUp(KeyUpEvent event) {
- alert("you press " + (char)event.getNativeKeyCode() + " up");
- }
- });
- Label label5 = new Label("Image event example");
- add(label5);
- final Image image = new Image("xx.jpg");
- add(image);
- image.addLoadHandler(new LoadHandler() {
- public void onLoad(LoadEvent event) {
- }
- });
- image.addErrorHandler(new ErrorHandler() {
- public void onError(ErrorEvent event) {
- image.setTitle("no such image");
- }
- });
- HTML html = new HTML("<div></div>");
- html.setSize("300", "300");
- DOM.setStyleAttribute(html.getElement(), "border", "solid 1px");
- add(html);
- html.addMouseOverHandler(new MouseOverHandler() {
- public void onMouseOver(MouseOverEvent event) {
- alert("mouse over");
- }
- });
- html.addMouseMoveHandler(new MouseMoveHandler() {
- public void onMouseMove(MouseMoveEvent event) {
- alert(event.getClientX() + ":" + event.getClientY());
- }
- });
- html.addMouseOutHandler(new MouseOutHandler() {
- public void onMouseOut(MouseOutEvent event) {
- alert("mouse out");
- }
- });
- html.addMouseUpHandler(new MouseUpHandler() {
- public void onMouseUp(MouseUpEvent event) {
- alert("mouse up");
- }
- });
- ScrollPanel panel = new ScrollPanel();
- panel.setSize("100", "30");
- 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."));
- add(panel);
- panel.addScrollHandler(new ScrollHandler() {
- public void onScroll(ScrollEvent event) {
- box.setText("Scorll!!!");
- }
- });
- TextArea area = new TextArea();
- area.setSize("150", "150");
- 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.");
- area.addMouseWheelHandler(new MouseWheelHandler() {
- public void onMouseWheel(MouseWheelEvent event) {
- alert("mouse wheel occur!");
- }
- });
- add(area);
- final Grid grid = new Grid(3 , 3);
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- grid.setText(i, j, "Cell(" + i + " , " + j + ")");
- }
- }
- grid.setBorderWidth(1);
- add(grid);
- grid.addTableListener(new TableListener() {
- public void onCellClicked(SourcesTableEvents sender, int row,
- int cell) {
- DOM.setStyleAttribute(((Grid)(sender)).getCellFormatter().getElement(row, cell), "border", "3px solid #f00");
- }
- });
- Tree tree = new Tree();
- tree.addItem("Item1");
- tree.addItem("Item2");
- tree.addItem("Item3");
- tree.addItem("Item4");
- tree.addTreeListener(new TreeListener() {
- public void onTreeItemSelected(TreeItem item) {
- alert(item.getText() + " selected");
- }
- public void onTreeItemStateChanged(TreeItem item) {
- alert(item.getText() + " changed");
- }
- });
- add(tree);
- }
- public void add(Widget element) {
- RootPanel.get().add(element);
- }
- public void alert(String src) {
- Window.alert(src);
- }
- public String getEventType(DomEvent<?> event) {
- return event.toString();
- }
- }
GWT事件处理的更多相关文章
- GWT资料收集
1.别人的GWT笔记 http://www.blogjava.net/peacess/archive/2007/08/06/84950.html 2.GWT系统类库参考手册 http://www.bo ...
- JavaScript权威设计--事件处理介绍(简要学习笔记十七)
1.事件相关概念 事件类型:一个用来说明发生什么类型事件的字符串 事件目标:是发生的事件或与之相关的对象. 事件处理程序(事件监听程序):是处理货响应事件的函数. 事件对象:是与特定事件相关并且包含有 ...
- JavaScript移除绑定在元素上的匿名事件处理函数
前言: 面试的时候有点蒙,结束之后想想自己好像根本就误解了面试官的问题,因为我理解的这个问题本身就没有意义.但是当时已经有一些思路,但是在一个点上被卡住. 结束之后脑子瞬间灵光,想出了当时没有迈出的那 ...
- linux输入子系统(input subsystem)之evdev.c事件处理过程
1.代码 input_subsys.drv.c 在linux输入子系统(input subsystem)之按键输入和LED控制的基础上有小改动,input_subsys_test.c不变. input ...
- 【repost】JavaScript 事件模型 事件处理机制
什么是事件? 事件(Event)是JavaScript应用跳动的心脏 ,也是把所有东西粘在一起的胶水.当我们与浏览器中 Web 页面进行某些类型的交互时,事件就发生了.事件可能是用户在某些内容上的点击 ...
- 【原】iOS学习之事件处理的原理
在iOS学习23之事件处理中,小编详细的介绍了事件处理,在这里小编叙述一下它的相关原理 1.UITouch对象 在触摸事件的处理方法中都会有一个存放着UITouch对象的集合,这个参数有什么用呢? ( ...
- android事件处理之基于监听
Android提供了了两种事件处理方式:基于回调和基于监听. 基于监听: 监听涉及事件源,事件,事件监听器.用注册监听器的方法将某个监听器注册到事件源上,就可以对发生在事件源上的时间进行监听. 最简单 ...
- Nova PhoneGap框架 第七章 设备事件处理
我们的框架包含了几种设备事件的处理,目的是为了让我们的程序员更容易的完成代码.这些事件包括:回退键(Android)和横竖屏切换事件. 7.1 Android回退键 首先来说说回退键的事件处理.当用户 ...
- 译:DOM2中的高级事件处理(转)
17.2. DOM2中的高级事件处理(Advanced Event Handling with DOM Level 2) 译自:JavaScript: The Definitive Gu ...
随机推荐
- 字符串匹配的python实现
所有字符串匹配算法的核心问题是,当出现不匹配时,如何向后移动模式串 一.暴力匹配算法 如果要匹配一个字符串s 和一个模式串p,则从i=0开始依次匹配s[i:(i+len(p))],简单粗暴,代码如下: ...
- Instruments --- 内存泄露
虽然iOS 5.0版本之后加入了ARC机制,由于相互引用关系比较复杂时,内存泄露还是可能存在.所以了解原理很重要. 这里讲述在没有ARC的情况下,如何使用Instruments来查找程序中的内存泄露, ...
- canvas仿黑客帝国的字符下落
? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 ...
- JVM 学习笔记(一)
JVM ----Java Virtual Machine (熟称:JAVA虚拟机),JVM 在执行JAVA程序的过程中将内容划分为若干个区域,其有各自的用途和管理机制.如下图: 1. 程序计 ...
- 【BZOJ 3529】 [Sdoi2014]数表 (莫比乌斯+分块+离线+树状数组)
3529: [Sdoi2014]数表 Description 有一张N×m的数表,其第i行第j列(1 < =i < =礼,1 < =j < =m)的数值为能同时整除i和j的所有 ...
- 在KEIL中的模块化程序写法
在使用KEIL的时候,我们习惯上在一个.c的文件中把自己要写的东西按照自己思路的顺序进行顺序书写.这样是很普遍的写法,当程序比较短的时候比如几十行或者一百多行,是没有什么问题的.但是当程序很长的时候, ...
- gunicorn启动报错gunicorn.errors.HaltServer
启动gunicorn报错: # gunicorn -b :9008 -w 2 webserver:app 2013-12-10 09:12:58 [29701] [INFO] Starting gun ...
- C# WinForm窗体界面设置问题
设置方法: 一:Form对象 属性: 设计中的Name:窗体类的类名AcceptButton:窗口的确定按钮CancelButton:窗口按ESC的取消按钮 1.外观 Backcolor:背景颜色Fo ...
- C#面向对象的三大特征
一,封装:我们可以把世界上任何一个东西都看作为一个对象,那么我们这里以人为例,一个人就肯定是一个对象了.那么封装是什么呢?封装就是这个人要完成一件事情,他所需要的任何工具都带在了自己的身上,所需要的技 ...
- [SDJX2015]面积
[问题描述:] 一个六边形的每个内角均为120°,按顺时针给定它每条边的长度,求它的面积与边长为1的等边三角形的面积的比值. [输入:] 一行六个整数a,b,c,d,e,f,表示六条边的长度. [输出 ...