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 ...
随机推荐
- 配置mybatis流程
使用mybatis的优点: 1. 易于上手和掌握. 2. sql写在xml里,便于统一管理和优化. 3. 解除sql与程序代码的耦合. 4. 提供映射标签,支持对象与数据库的orm字段关系映射 5. ...
- Learn Docker
Learn Docker A Container is to VM today, what VM was to Physical Servers a while ago. The workload s ...
- bzoj 2706: [SDOI2012]棋盘覆盖 Dancing Link
2706: [SDOI2012]棋盘覆盖 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 255 Solved: 77[Submit][Status] ...
- Word添加带圈文字
这个在项目有编号李没有,只能一个一个输入 A.开始------------字体里选择带圈的字符号 B.插入,符号里选编号
- PowerDesigner从SqlServer 数据库中导入实体模型
此篇是之前写的,从我的CSDN博客挖过来的- 一.开启数据库服务并配置ODBC数据源 1.开启数据库服务 (1)通过SQL Server Configuration Manager配置工具启动SQL ...
- 李洪强iOS开发之-环信02.2_环信官网下载环信 SDK
李洪强iOS开发之-环信02.2_环信官网下载环信 SDK 移动客服即时通讯云 iOS SDK 当前版本:V3.1.4 2016-07-08 [ 版本历史 ] | 开发指南 | 知识库 | Demo源 ...
- BZOJ_1901_&_ZJU_2112_Dynamic_Rankings_(主席树+树状数组/线段树+(Treap/Splay))
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1901 给出一个长度为n的数列A,有m次询问,询问分两种:1.修改某一位置的值;2.求区间[l, ...
- 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色
原文网址:http://www.cnblogs.com/myphoebe/archive/2012/01/06/2314728.html android中设置TextView的颜色有方法setText ...
- (转载)AS3中的mouseEnabled与mouseChildren
(转载)http://www.cnblogs.com/gongchen/archive/2013/05/09/3069055.html mouseEnabled与mouseChildren都是用来确定 ...
- RatingBar设置显示星星个数
RatingBar评分控件 项目中遇到问题 marker一下: 关于自定义以及遇到的出现模糊情况 多半是因为切得图除颜色外 不一致的原因 如果大小也不一样,(沃日) 问题是这样的: 我可以通过OnRa ...