The button and the label are added to the
RootPanels associated with the host HTML page table cell elements. A
4.3 Creating a GWT Application 65
RootPanel is a panel to which all other widgets are added. The Widget
class is the root class for most of the user interface (UI) components.
CatalogForm.java is listed below.
package com.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Entry point classes define
onModuleLoad().
*/
public class CatalogForm implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final Button button = new Button(???Click me???);
final Label label = new Label();
button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if (label.getText().equals(??????))
label.setText(???Hello World!???);
else
label.setText(??????);
}
});
// Assume that the host HTML has elements defined
whose
// IDs are ???slot1???, ???slot2???. In a real app, you
probably would not want
// to hard-code IDs. Instead, you could, for
example, search for all
// elements with a particular CSS class and
replace them with widgets.
//
RootPanel.get(???slot1???).
Pages:
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78