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 ...
随机推荐
- 如何彻底删除PPA软件库
添加一个PPA源 sudo add-apt-repository ppa:user/ppa-name 如添加cairo-dock到weekly update源 sudo add-apt-reposit ...
- LFS实践
用了三天,编译了两次LFS,把LFS的基本流程和原理都弄清了.用的是LFS 6.3,使用的教程是LFS速成手册(6.3) ,感觉很不错,如果按照它的做法,一步一步来,基本都能编译成功而且没什么错误.不 ...
- VPS用LNMP安装WordPress
前言 前几天,朋友手头上有一个空闲的vps,256M内存,我决定拿来玩一下.经过一番思考,还是用来挂站吧.然后看是CentOS6系统,果断决定用从来没玩过的LNMP.于是,百度.谷歌找教程,好多教程都 ...
- android app修改包名
change package nameA.使用到得工具 notepad++,everything搜索工具(C:\Users\Administrator\Desktop\MusicScanResu ...
- MATLAB conv2卷积的实现
MATLAB conv2卷积的实现 二维卷积的算法原理比较简单,参考任意一本数字信号处理的书籍,而matlab的conv2函数的滤波有个形状参数,用下面的一张图很能说明问题: 这里给出一种最原始的实现 ...
- 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)
Walking Race Description flymouse's sister wc is very capable at sports and her favorite event is ...
- android ListView异步加载图片(双缓存)
首先声明,参考博客地址:http://www.iteye.com/topic/685986 对于ListView,相信很多人都很熟悉,因为确实太常见了,所以,做的用户体验更好,就成了我们的追求... ...
- 使用@ResponseBody 出现错误Could not find acceptable representation
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representatio ...
- 根据指定的commit查找对应的log
find commit by hash sha in git 问题: I need to find a commit in Git by given hash SHA. For example, if ...
- Apache Commons IO 2.3 几点用法
//直接将IO流转成字符串 InputStream in = new URL( "http://jakarta.apache.org" ).openStream(); try { ...