My favorites | Sign in
Google
                
Search
for
Updated Aug 28, 2008 by galgwt.reviews
DevGuideClientSide  
"Client-side" refers to source code that is intended to be translated and run in a web browser as JavaScript.

Client-side Code

Your application is sent across a network to a user, where it runs as JavaScript inside his or her web browser. Everything that happens within your user's web browser is referred to as client-side processing. When you write client-side code that is intended to run in the web browser, remember that it ultimately becomes JavaScript. Thus, it is important to use only libraries and Java language constructs that can be translated.

Module EntryPoint Class

To begin writing a GWT module, you must create a subclass of the EntryPoint class.

package com.example.foo.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Foo implements EntryPoint {

  /**
   * This is the entry point method.  Initialize you GWT module here.
   */
  public void onModuleLoad() { 

    // Writes Hello World to the Hosted Mode log window.
    GWT.log("Hello World!", null);
  }
}

Typically, the code inside of onModuleLoad() will create new user interface components, setup listeners for events, and/or modify the browser DOM in some way. The above example simply logs a message to the hosted mode console. Thus if you try to deploy it, you won't see anything (GWT.log() is compiled away when deploying to web mode)

Tip: The applicationCreator command-line tool creates a starter application for you with a sample EntryPoint subclass defined.

Hello World Example

Included with the GWT distribution is a sample "Hello World" program that creates a simple user interface.

package com.google.gwt.sample.hello.client;

import com.google.gwt.core.client.EntryPoint;
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.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * HelloWorld application.
 */
public class Hello implements EntryPoint {

  public void onModuleLoad() {
    Button b = new Button("Click me", new ClickListener() {
      public void onClick(Widget sender) {
        Window.alert("Hello, AJAX");
      }
    });

    RootPanel.get().add(b);
  }
}

Notice that in the onModuleLoad() entry point, the following actions were taken:

Here is what the application looks like when run in hosted mode browser:


Sign in to add a comment