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学习_数据处理编程实例(二)
在上一节python学习_数据处理编程实例(二)的基础上数据发生了变化,文件中除了学生的成绩外,新增了学生姓名和出生年月的信息,因此将要成变成:分别根据姓名输出每个学生的无重复的前三个最好成绩和出生年 ...
- cocos2d-x笔记4: TextField不能删除内容,以及我的解决办法。。。
3.0正式版,win32下,TextField按下backspace键不能删除内容.网上搜了下,很早就有的问题了,正式版了竟然还不解决... 真心无力吐槽啊!!!这种巨大而又明显的Bug... 从昨天 ...
- 【原】jQuery编写插件
分享一下编写设置和获取颜色的插件,首先我将插件的名字命名为jquery.color.js.该插件用来实现以下两个功能1.设置元素的颜色.2.获取元素的颜色. 先在搭建好如下编写插件的框架: ;(fun ...
- html 各个标签初始化
html,body,div,ul,li,ol,h1,h2,h3,h4,h5,h6,span,input{ margin:0;padding:0;}body{font:12px/1.5em " ...
- UM_第三方登录
参考官方文档(http://dev.umeng.com/social/ios/detail-share#7), 做出以下总结. 第三方登录主要用于简化用户登录流程,通过用户拥有的微博.QQ.微信等第三 ...
- spirng MVC乱码过滤器
<filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>or ...
- android app修改包名
change package nameA.使用到得工具 notepad++,everything搜索工具(C:\Users\Administrator\Desktop\MusicScanResu ...
- 设计模式之策略模式Strategy
/** * 策略设计模式 * 策略模式:定义一系列的算法族,使他们之间可以相互转换,动态的改变其行为. * 问题:设计一个鸭子模拟游戏. * 现在有一群鸭子: * ①这些鸭可以有飞的行为(分为快和慢) ...
- vs2015 Xamarin.Android安装
原文:vs2015 Xamarin.Android安装 Xamarin.Android 安装步骤,以vs2015为例 1,安装vs2015中的跨平台项,但是安装在国内肯定失败,因为需要到谷歌下载 当我 ...
- Android应用架构
Android开发生态圈的节奏非常之快.每周都会有新的工具诞生,类库的更新,博客的发表以及技术探讨.如果你外出度假一个月,当你回来的时候可能已经发布了新版本的Support Library或者Play ...