https://developers.google.com/web-toolkit/doc/latest/DevGuideUiHandlers
Events in GWT use the handler model similar to other user interface frameworks. A handler interface defines one or more methods that the widget calls to announce an event. A class wishing to receive events of a particular type implements the associated handler interface and then passes a reference to itself to the widget to subscribe to a set of events. The Button class, for example, publishes click events. The associated handler interface is ClickHandler.
The following example demonstrates how to add a custom ClickHandler subclass to an instance of a Button:
public void anonClickHandlerExample() {
Button b = new Button("Click Me");
b.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// handle the click event
}
});
}
Using anonymous inner classes as in the above example can use excessive memory for a large number of widgets, since it results in the creation of many handler objects. Instead of creating separate instances of the ClickHandler object for each widget that needs to be listened to, a single handler can be shared between many widgets. Widgets declare themselves as the source of an event when they invoke a handler method, allowing a single handler to distinguish between multiple event publishers with an event object's getSource() method. This makes better use of memory but requires slightly more code, as shown in the following example:
public class HandlerExample extends Composite implements ClickHandler {
private FlowPanel fp = new FlowPanel();
private Button b1 = new Button("Button 1");
private Button b2 = new Button("Button 2");
public HandlerExample() {
initWidget(fp);
fp.add(b1);
fp.add(b2);
b1.addClickHandler(this);
b2.addClickHandler(this);
}
public void onClick(ClickEvent event) {
// note that in general, events can have sources that are not Widgets.
Widget sender = (Widget) event.getSource();
if (sender == b1) {
// handle b1 being clicked
} else if (sender == b2) {
// handle b2 being clicked
}
}
}
分享到:
相关推荐
标题"PyPI 官网下载 | django-channels-handlers-0.2.0.tar.gz"指的是这个资源是从Python的官方软件包仓库PyPI(Python Package Index)下载的,文件名为"django-channels-handlers-0.2.0.tar.gz"。这表明它是一个...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,亲测可用
最后,“Searching”部分概述了Solr中的搜索过程,描述了搜索中使用的主要组件,包括请求处理器(request handlers)、查询解析器(query parsers)和响应编写器(response writers)。这部分内容对于构建功能强大的...
本文将深入探讨“connect-assetmanager-handlers-updated”这一前端开源库的更新,以及它如何增强Connect AssetManager的功能。 Connect AssetManager是一款基于Node.js的中间件,用于构建动态Web应用。它特别关注...
开源项目-gorilla-handlers.zip,gorilla/handlers: A collection of useful handlers for Go's net/http package
本课程“Adding-Event-Handlers_lesson”聚焦于如何有效地使用事件处理程序,特别是JavaScript中的`addEventListener()`方法。这个方法是DOM(文档对象模型)级别2中的一个功能,用于将一个或多个事件处理器添加到...
“Uploading Data with Index Handlers”和“Uploading Structured Data Store Data with the Data Import Handler”部分分别介绍了使用索引处理器上传数据和使用数据导入处理器上传结构化数据存储数据的方法。...
在`fabric-am-handlers-0.8.tar.gz`压缩包中,我们可以预期找到以下内容: 1. `fabfile.py` 或 `fabfile.py.example`:这是Fabric的工作文件,其中定义了可执行的任务和操作。用户可以在这个文件中编写自定义的任务...
This application demonstrates how to use the Format and Parse event handlers when data binding Windows Form controls. The Format event fires when the data is transferred the data source to the bound ...
`laravel-exception-handlers` 主题深入探讨了在Laravel 5中如何定制和管理异常处理。 1. **异常处理基础** - 在PHP中,异常是通过`throw`语句引发,并通过`try-catch`块来捕获和处理。Laravel扩展了这个概念,...
标题中的“connect-assetmanager-handlers-updated”指的是一个针对前端开发的开源库,它与Node.js中的Connect框架紧密相关。Connect是Express.js的基础,是一个轻量级的HTTP服务器中间件,广泛用于构建Web应用程序...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
资源分类:Python库 所属语言:Python 资源全名:django-ohm2-handlers-light-0.1.19.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用
官方版本,亲测可用