GWT:我要创建事件和事件处理程序类吗?

GWT:我要创建事件和事件处理程序类吗?,gwt,Gwt,我有一个与数据库通信的gwt项目 应用程序设计mvp模式和视图有一个输入表单、一个网格和许多按钮 根据gwt教程,每个事件都有一个事件类、一个事件处理程序类和presenter中的initialize事件处理程序类 那么,如果事件的数量是不可数的,我是否要创建事件和事件处理程序类 [示例包]: src/com/example/event/${A Lot Of event} src/com/example/event/${许多事件处理程序} src/com/example/presenter/${

我有一个与数据库通信的gwt项目

应用程序设计mvp模式和视图有一个输入表单、一个网格和许多按钮

根据gwt教程,每个事件都有一个事件类、一个事件处理程序类和presenter中的initialize事件处理程序类

那么,如果事件的数量是不可数的,我是否要创建事件和事件处理程序类

[示例包]:

src/com/example/event/${A Lot Of event}

src/com/example/event/${许多事件处理程序}

src/com/example/presenter/${A presenter}


src/com/example/view/${A view}

我喜欢将事件处理程序(如果创建了has处理程序接口,还可以选择has处理程序接口)作为事件本身的内部类(好的,接口)。通常看起来像这样:

public class MyAppEvent extends GwtEvent<MyAppEventHandler> {

    //... event guts, dispatch, getAssociatedType, etc


    public interface MyAppEventHandler extends EventHandler {
        void onMyAppEventHappened(MyAppEvent event);
    }


    // and optionally, if you only register handlers through add methods
    public interface HasMyAppEventHandlers {
        void addMyAppEventHandler(MyAppEventHandler handler);
    }
}
公共类MyAppEvent扩展了GwtEvent{
//…事件类型、调度、getAssociatedType等
公共接口MyAppEventHandler扩展了EventHandler{
在发生上诉时无效(我的上诉事件);
}
//或者,如果您仅通过add方法注册处理程序
公共接口有MyAppEventHandler{
void addMyAppEventHandler(MyAppEventHandler处理程序);
}
}