如何使用GWT设置和/或处理onload事件 [英] How do I setup for and/or handle onload event with GWT
问题描述
这是一个非常基本的问题,但是我无法通过Google或这个网站找到任何关于如何做到这一点的事情,这真是令人沮丧,因为我已经通过了GWT教程。
This has to be a pretty basic question but I cannot for the life of me find anything via Google or this site about how to do this and it's really frustrating because I've gone through the GWT tutorial.
我正在尝试将一个JavaScript项目转换为GWT。现在我正在尝试将转换为GWT等效的东西。我看过RootPanel,看不到任何东西。
I'm trying to convert a javascript project I have to GWT. Right now I am trying to convert "" to something GWT equivalent. I've looked at RootPanel and I can't see anything.
显然,我在GWT中缺少一些基本的东西?
Obviously I'm missing something fundamental in GWT ?!
推荐答案
GWT中的大部分小部件和面板都实现了 HasAttachHandlers 界面。向这些小部件/面板添加一个AttachEvent.Handler相当于定义一个运行onload的函数。
Most widgets and panels in GWT implements the HasAttachHandlers interface. Adding an AttachEvent.Handler to these widgets/panels is equivalent to defining a function to run onload.
一个例子:
FlowPanel mainPanel = new FlowPanel();
mainPanel.addAttachHandler(new AttachEvent.Handler() {
@Override
public void onAttachOrDetach(AttachEvent event) {
// do something
}
});
这篇关于如何使用GWT设置和/或处理onload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!