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(Google Web Toolkit)是由Google推出的开源JavaScript开发框架,它让Java开发者可以使用Java编写Web应用,并自动生成优化的JavaScript代码,运行在客户端。本教程详细介绍了GWT的基础入门、进阶技能以及高级应用,覆盖从安装配置、基础组件使用到复杂RPC通信、性能优化和自定义组件开发等... 阅读详情

相关推荐

GNSS接收机性能测试全攻略:从实验室到真实场景

本文系统介绍了GNSS接收机从实验室到真实场景的完整性能测试流程。首先通过GNSS模拟器进行射频传导测试,评估接收机的基础性能;其次进行天线OTA测试,考察整机系统表现;最后通过精心设计的外场路测,在复杂环境中验证其实际定位精度与可靠性。文章强调,只有结合可控的实验室验证与多变的外场挑战,才能对接收机性能做出全面、真实的评价。

weixin_28365523的博客 526

定时器setTimeout()、setInterval()详解

JavaScript 标准参考教程(alpha) 浏览器对象 定时器 GitHub  TOP  定时器 来自《JavaScript 标准参考教程(alpha)》,by 阮一峰 目录

风动之石的专栏 1万+

GQA数据集介绍

GQA,这是一个用于真实世界视觉推理和组合问答的新数据集。2200万个不同的推理问题,所有这些问题都带有表示其语义的功能程序。答案分布受到严格控制。11.3万张图像、2200万个问题,推理能力有对象和属性识别、传递关系跟踪、空间推理、逻辑推理和比较。

qq_56551150的博客 2961

GWT中的事件与监听器

在GWT应用程序运行时,当用户单击鼠标或按下键盘,GWT都会产生一个事件来相应用户的请求。所谓事件就是指在应用程序中我们关心的某些事情发生了,然后应用程序去处理这些事件。对这些事件做出相应的程序就叫做事件处理器。 GWT所支持的事件和java有些不同,因为GWT是WEB应用程序,所有GWT所支持的事件应该是web浏览器事件GWT支持浏览器可以捕获的所有事件,GWT所能捕获的事件请参考com.go

T` 5040

步进电机 cia402协议 报文自己的理解 (笔记)

步进电机 cia402协议 报文自己的理解 (笔记)

she666666的博客 3822

弥散圆以及最大弥散圆

1弥散圆的形成? 原本景物中的一点应该经过透镜本应该也是一点才对。但是因为离焦,球差的存在,最终成像会投影成一个光斑圆圈。越小越清晰,越大就互相干涉变得越模糊。 同时人们规定二零最大弥散圆,就是人眼能够感受清晰模糊的一个边界,直径大于它,感受到模糊;直径小于它,感受不到模糊。 下面分别是离焦(左),球差(右)。 2弥散圆大小怎么计算呢? ,f为焦距;<1> ,D为光圈有效孔径;<2> F=f/D; <3> 3条公式合并可得出: ...

camerall 3122

【译】GWT入门:构建用户界面

【译自:https://developers.google.com/web-toolkit/doc/latest/tutorial/buildui?hl=zh-CN】   到此,我们已经创建了StockWatcher工程,也审视了功能需求和界面元素。   这一切,我们要开始使用GWT提供的控件和面板来构建用户界面。   GWT已经处理了很多跨浏览器的兼容问题。因此,如果你是基于GWT的...

刘刚的空间 505

Transformer-LSTM预测 | 基于Transformer-LSTM的多变量单步时间序列预测(Matlab)

Transformer-LSTM预测 | 基于Transformer-LSTM的多变量单步时间序列预测(Matlab)

机器学习之心的博客,关注并私信文章链接,获取对应文章源码和数据。 195

gwt利用HandlerManager创建event事件

gwt利用HandlerManager创建event事件By 王军, 2010年02月1日 11:49 下午    在学习和使用gwt过程中,会使用到大量的事件处理,是利用各个组件的监听器来完成的,很方便。但是有些情况我们需要自己定义一个事件,用来创建监听器。就像下面例子中的,当点击删除时,在另一个类中创建了一个对话框,当点击确认之后要把此事件告送给当前类,那么就需要在当前类里面创建监

junpeng88的专栏 1584

数据分析案例-车辆二氧化碳排放量数据可视化分析

本实验数据集来源于Kaggle,该数据集捕获了车辆二氧化碳排放量随不同特征变化的详细信息。数据集取自加拿大政府官方开放数据网站。其中包含 7 年期间的数据。总共有 7385 行和 12 列。各列变量含义解释如下:Make:车辆的品牌或制造商。Model:车辆的具体车型名称。Vehicle Class:车辆的分类,如紧凑型、SUV等。Engine Size(L):车辆发动机的尺寸,以升为单位。Cylinders:车辆发动机的气缸数。

m0_64336780的博客 1万+

Autosar NvM配置-手动配置Nvblock及使用-基于ETAS软件

NVM作为存储协议栈中最顶层的模块,是必须要掌握的。目前项目基本使用MCU带的Dflash模块,使用Fee模拟eeprom。在项目前期阶段,应该充分讨论需要存储的内容,包括应用数据,诊断数据等,用以评估Dflash空间是否够用。本文基于ETAS软件介绍NVBlock配置生成NVM参数及使用。使用NVBlock配置生成,基本不用手写代码,还是比较方便的。对于Nv block的划分,建议将同时写的一类数据放到一个block中,因为block除了data以外,Fee还会增加一些header数据,占用不少内存。

赞的博客 1895

题解:洛谷 P14357 [CSP-J 2025] 拼数

等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。小 R 想知道,在他所有能拼成的正整数中,最大的是多少。你需要帮助小 R 求出他能拼成的正整数的最大值。小 X 给了小 R 一个字符串。输出一行一个正整数,表示小 R 能拼成的正整数的最大值。中的任意多个数字,按任意顺序拼成一个正整数。,表示小 X 给小 R 的字符串。#普及-# #其他排序#洛谷:[P14357。

团爸讲算法 1399

gwt事件原理

GWT事件原理   1.事件处理方式 当浏览器html标签的事件被触发时,GWT会把事件的处理转发到Widget.onBrowserEvent(Event event)方法进行浏览器事件与GWT事件的转换,调用GWT中定义的事件处理!在此可以收集所有事件的相关信息!   2.GWT事件...

chensir1985的专栏 236

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

GWT 入门介绍

GWT 入门介绍GWT使用JSON格式的数据通讯  GWT是 Google Web Toolkit的简称。 GWT是一个以Java语言为工具,以类似Swing的方式编写UI组件,之后通过GWT Compiler编译 为JavaScritp和HTML在客户端浏览器中运行的一个开发工具和编程模型。  GWT应用程序有两种方式运行:Hosted Model     在

Struts 2 的专栏 3万+

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

GWT中sinkEvent方法的用途

sinkEvent是指为GWT控件注册一些事件。比如TextBox会响应OnKeyPressed事件的原因是因为TextBox的实现中使用了sinkEvent(GWT实现)。sinkEvent对于我们的用处在于,当我们使用DOM方式或者继承Widget或者通过继承Composite实现Composite Widget时,可以将我们需要的一些Event通过sinkEvent...

weixin_34128534的博客 147

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

gwt 实现界面模式之 "Extras on Demand"

GWT 是一个强大的工具, 一旦定义好html结构和css之后,使用gwt提供的组件模型,可以将任意结构的html+css封装成为组件 ,并在java 语言中以组件的方式操作.GWT 1.6 增加了新的事件系统(原有的事件api可能会在将来删除), 更使得在dom或者现有的组件之上扩展开发相当容易.下面将以一个例子说明如何使用新的事件模型扩展现有组件. (使用最新的 gwt 1.6.4 )...

imduker的专栏 258

Google GWT

最近发布的 Google Web Toolkit (GWT) 是一组全面的 API 和工具,它支持用户几乎完全使用 Java™ 代码来创建动态 Web 应用程序。Philip McCarthy 回到了他广受欢迎的面向 Java 开发人员的 Ajax 系列,向您展示 GWT 能做什么,并帮助您确定它是否适合您。 GWT(请参阅 参考资料)采用了一种不寻常的方式进行 Web 应用程序开发。它没有

u014625500的专栏 743

[转载]借助传统方法使用高级 GWT 控件

借助传统方法使用高级 GWT 控件Google Web Toolkit (GWT) 提供了很多库和工具让您可以在 Java™ 编程语言中开发 Ajax 应用程序。但是 GWT 的 UI 控件(小部件)标准库并不提供现代企业应用程...

congji3817的博客 137

GWT - GWT Designer开发Ajax应用 (06) - 常用控件使用

http://blog.csdn.net/pathuang68/article/details/4272424 概要说明: Tab、RadioButton和ComboBox的使用方法。 1. 创建一个GWT Java Project   图1 设定项目名称为:TestSeveralWidgets,点击Finish按钮:     图2 做一下工作: - 选中Creat...

WisonKot 198

使用UIBinder的GWT自定义按钮

这是一个有关如何在GWT上使用UIBinder创建自定义按钮的示例。 public class GwtUIBinderButton implements EntryPoint { public void onModuleLoad() { Button button = new Button(); button.setText("Button"); button.addC...

最佳 Java 编程 271

GWT Tutorials节选

本文写的乱七八糟..只作为自己回忆之用 需要下载Google插件提供开发的便利 建立专门的工程后,直接使用run进行运行,提供了后台的请求支持--接收请求信息 Tutorials 教程部分 widgets组件 FlexTable组件,提供了灵活的表格,不需要知道多少列,能够方便的进行添加行 Buttons组件,使用div构建的,跨平台按钮--相同的样式 Inp...

天水一方 165
上一篇: GWT中各种Panel
下一篇: 中英文所占字节数
java_mail_test
博客等级 码龄18年 1粉丝 299原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值