package com.javatpoint.helloworld.client;
import com.google.gwt.core.client.EntryPoint;
/** * Entry point classes define onModuleLoad() */
public class SampleWebApplication implements EntryPoint {
/ * This is the entry point method. */
public void onModuleLoad() {
// TODO
}
}
package com.javatpoint.helloworld.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
/**
* Entry point classes define onModuleLoad().
*/
public class SampleWebApplication implements EntryPoint {
/** A vertical panel that hold other components over UI.*/
VerticalPanel vPanel;
/*
* A label that gets updated on click of button.
*/
Label lbl;
/**
* This is the entry point method.
*/
public void onModuleLoad() {
vPanel= new VerticalPanel ();
lbl= new Label ();
/*
* Button and its click handlar.
*/
Button btn = new Button("GWT Button");
btn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
lbl.setText("You clicked GWT Button!");
}
});
/*
* adding label and button into Vertical Panel.
*/
vPanel.add(lbl);
vPanel.add(btn);
/*
* Adding vertical panel into HTML page.
*/
RootPanel.get().add(vPanel);
}
}
运行GWT Web应用程序
GWT Web应用程序以两种模式运行:
开发模式:在这种模式下,Java代码会运行到JVM中
生产模式:在这种模式下,GWT编译器将编译Java代码并创建在浏览器上运行的JavaScript。
在本教程中,我们将GWT Web应用程序运行到“ GWT Super Dev Mode”中,该模式在运行时编译Java代码并在浏览器上运行JavaScript。