Java/GWT/RootPanel
Add two controls to RootPanel
package com.jexp.gwt.client;
import com.google.gwt.core.client.*;
import com.google.gwt.user.client.ui.*;
public class GWTClient implements EntryPoint{
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("");
}
});
RootPanel.get("slot1").add(button);
RootPanel.get("slot2").add(label);
}
}
Use RootPanel to Load New Page
package com.jexp.gwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
public class GWTClient implements EntryPoint{
public void onModuleLoad() {
loadLoginView();
}
private void loadLoginView() {
final Label loginPrompt = new Label("login");
final Grid grid = new Grid(3, 2);
final Label namePrompt = new Label("name");
final TextBox nameTextbox = new TextBox();
final Label passwordPrompt = new Label("password");
final PasswordTextBox passwordTextbox = new PasswordTextBox();
final Button button = new Button("Login");
button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
loadWelcomeView();
}
});
button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
Window.alert("New page loaded");
}
});
loginPrompt.addStyleName("loginPrompt");
nameTextbox.addStyleName("nameField");
passwordTextbox.addStyleName("passwordField");
grid.setWidget(0, 0, namePrompt);
grid.setWidget(0, 1, nameTextbox);
grid.setWidget(1, 0, passwordPrompt);
grid.setWidget(1, 1, passwordTextbox);
grid.setWidget(2, 1, button);
RootPanel.get().clear();
RootPanel.get().add(loginPrompt);
RootPanel.get().add(grid);
}
private void loadWelcomeView() {
final Label welcomeMsg = new Label("welcome");
welcomeMsg.addStyleName("welcomeMsg");
RootPanel.get().clear();
RootPanel.get().add(welcomeMsg);
}
}