我在 GWT 中创建了一个自定义小部件,例如:
public class Header extends Composite {
private Button btnContribute;
public Header() {
btnContribute = new Button("Contribute");
}
} //This is only a sample - in actual there are few bundled widgets
在我的入口点类中,我将此自定义小部件用作我的 dockLayoutPanel 的北面板,如下所示:
public class MyClass implements EntryPoint {
private DockLayoutPanel dockLayoutPanel;
private ScrollPanel contentScrollPanel;
private Header header; //My custom widget
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
dockLayoutPanel = new DockLayoutPanel(Unit.EM);
rootPanel.add(dockLayoutPanel, 20, 10);
header = new Header();
dockLayoutPanel.addNorth(header, 7.7);
dockLayoutPanel.addSouth(new HTML("south"), 7.7);
dockLayoutPanel.addWest(new HTML("west"), 7.7);
contentScrollPanel = new ScrollPanel();
dockLayoutPanel.add(contentScrollPanel);
htmlContent = new HTML("content", true);
contentScrollPanel.setWidget(htmlContent);
htmlContent.setSize("100%", "100%");
}
}
我想在我的自定义小部件“btnContribute”中的按钮上创建一个 onClick 事件处理程序,以便它动态更新“contentScrollPanel”,删除当前内容,并在其中加载一个表单。
问题是当我尝试在我的自定义小部件中创建事件处理程序时,我无法弄清楚我应该如何从我的入口点类中添加和删除小部件..