`
starbhhc
  • 浏览: 649527 次
  • 性别: Icon_minigender_2
  • 来自: 深圳
社区版块
存档分类
最新评论

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实现文件上传" ...这个过程涉及到的知识点包括GWT事件处理、HTTP协议、文件流操作、Multipart/form-data格式、服务器端文件处理和错误处理等。掌握这些知识点可以帮助你理解和实现GWT环境下的文件上传功能。

    GWT 简单实例,包括添加/删除/修改/查询数据

    1. **GWT事件处理**:GWT提供了丰富的事件处理机制,包括点击事件、键盘事件、鼠标事件等。开发者可以通过实现事件监听器接口或者使用匿名内部类来响应这些事件。例如,在这个实例中,可能会有按钮的点击事件触发...

    GWT-Events.pdf

    **GWT事件处理机制详解** 在GWT中,事件处理是其核心特性之一,它提供了多种方式来管理用户界面的交互。文档中提到的主要事件处理方法包括: 1. **分离监听器类**:这是最常见的方法,即创建一个独立的类来实现...

    GWT in pratice

    3. **GWT事件处理**:介绍如何处理用户交互,包括键盘、鼠标事件和自定义事件。 4. **数据绑定和模型-视图-控制器(MVC)**:阐述GWT中的数据绑定机制,以及如何实现MVC模式来组织代码。 5. **GWT RPC和服务**:讲解...

    jqm4gwt-standalone-1.3.5.zip

    通过这个插件,开发者可以轻松地在GWT的Widget中嵌入Datebox,实现与GWT事件处理系统的交互,如数据绑定、验证等。这极大地简化了开发流程,降低了学习曲线,使得非JavaScript熟练的开发者也能构建出具有高级日期...

    gwt 练习 gwt学习

    5. **事件处理**:GWT中的事件处理机制允许用户与界面交互。你可以通过添加事件监听器来响应用户的点击、键盘输入等操作。 6. **RPC通信**:GWT的Remote Procedure Call (RPC)机制使得客户端和服务器之间能进行数据...

    GWT入门 GWT中文教程

    “GWT入门”和“GWT中文教程”显然是针对初学者的,它们可能从最基础的GWT安装、项目配置开始,逐步讲解GWT的核心概念,如UI设计(Widget系统)、事件处理、数据模型和服务器通信(RPC机制)、本地存储、国际化等。...

    GWT快速开发(GWT) 是一个Java软件开发框架用于开发类似于Google Maps和Gmail的AJAX应用程序。GWT的设计参考Java AWT包设计,类命名规则、接口设计、事件监听等。你可以用Java编程语言开发你的界面,然后用GWT编译器将Java类转换成适合浏览器执行的...

    - 支持事件处理机制,如点击事件、键盘事件等。 4. **远程服务调用(RPC)**: - GWT支持通过远程过程调用(Remote Procedure Call, RPC)机制与服务器端进行通信。 - 开发者可以通过定义服务接口并实现相应的服务端...

    GWT开发环境JAVA

    3. **APIs**:GWT提供了大量JavaScript库,包括UI组件、事件处理、国际化、数据绑定、异步RPC通信等,这些APIs都是用Java封装的,方便开发者使用。 4. **Widget库**:GWT包含一个丰富的Widget库,涵盖了从按钮、...

    smartgwt最新版本GWT的DEMO

    3. **事件处理**:DEMO会演示如何注册事件监听器,处理用户交互,如点击、选择、提交等事件。 4. **样式和主题**:SmartGWT提供了一套完整的主题系统,可以在DEMO中看到如何切换和定制不同的界面风格。 5. **异步...

    GWT入门和进阶

    GWT提供了丰富的事件处理机制,如按钮点击、鼠标移动等,你可以通过`addClickListener`等方法来绑定事件处理器。 **4. 数据绑定与Model-View-Presenter模式** GWT支持数据绑定,使得UI组件的状态能自动与后台模型...

    smartgwt官方实例

    3. **事件处理**:事件驱动编程是GUI开发的重要部分。实例中展示了如何注册事件监听器、处理用户交互和触发的事件,这对于理解SmartGWT的事件模型非常有帮助。 4. **布局管理**:SmartGWT提供了多种布局管理器,如...

    gwt实例,基于gwt-windows-1.5.2

    3. **事件处理**:GWT支持事件驱动编程,允许你为UI组件添加事件监听器,处理用户的交互行为。例如,点击按钮触发一个函数,提交表单等。 4. **数据绑定**:GWT的Data Binding机制使你可以方便地将UI组件的状态与...

    Google plugin sdk GWT

    GWT还提供了丰富的功能,例如异步通信(RPC)、本地存储、事件处理、国际化支持、CSS样式和主题,以及强大的单元测试框架。此外,GWT社区还提供了许多第三方库,如GWT-Bootstrap和GWT-Platform,这些可以帮助开发者...

    GWT EXT 教程全集

    中级篇可能涉及更复杂的布局管理、数据绑定以及事件处理;进阶篇则可能包括自定义组件、动画效果、性能优化等内容。 "GWT+Quickview+-+by+elephi[1].dong+.mht"文件可能是一个关于GWT快速预览功能的教程或演示,...

    GWT-API 帮助文档

    3. **事件处理**:描述GWT的事件模型,包括事件监听、事件冒泡和事件处理函数的使用。 4. **数据绑定**:讲解如何实现视图与模型之间的数据同步,如ValueProxy、ValueProvider和CellWidget等概念。 5. **RPC服务**...

    GwtDemo helloworld

    3. **事件处理**:GWT通过事件监听机制处理用户交互。例如,当用户点击登录按钮时,会触发一个事件,该事件会被对应的事件处理器捕获,执行登录逻辑。 4. **验证逻辑**:为了确保有效的登录,通常会有对输入数据的...

    GWT中文教程(入门进阶)

    4. **事件处理**:GWT中的事件模型基于DOM事件,你可以为Widget绑定事件监听器,处理用户交互。 5. **CSS样式**:GWT支持内联CSS和外部CSS样式表,可以通过Java代码动态修改样式,实现富客户端界面的定制。 6. **...

    GWT API帮助文档

    2. **事件处理(Event Handling)**: GWT通过事件监听器接口(如ClickHandler、BlurHandler等)使事件处理变得简单。开发者可以方便地添加和移除监听器,实现对用户交互的响应。 3. **异步通信(RPC)**: GWT的...

    gwt-2.8.2 SDK 最新下载 google web toolkit

    4. **事件驱动和异步通信**:GWT使用类似于Java Swing的事件模型,简化了用户交互处理。同时,GWT的RPC(Remote Procedure Call)机制使得与服务器的异步通信变得简单,提高了用户体验。 5. **UI构建工具**:GWT...

Global site tag (gtag.js) - Google Analytics