Thursday, February 5, 2009

GWT Programming Concepts

GWT Programming Concepts

This tutorial will introduce the architecture of GWT. It is aimed at programmers with little or no Java experience, but with reasonable experience with other programming languages using object oriented programming.

GWT is a single application. It consists of a series of panels. There may be a single panel onto which other panels are places, or multiple panels. You create and place Widgets onto these panels. Widgets are items like hyperlinks, textbox's, buttons, etc. With each of these widgets you can attach event listeners that will be execute when appropriate. For example you can attach a click listener to a button and when the user clicks the button, the action will be performed.

The important part of GWT is that panels and widgets are added using Java code.
Each widget (which includes a Panel) is an object that is derived from a number of base classes. For example:

UIObject : the base class with properties or methods:

* Size
* Width
* toString

Widget : derived from UIObject (so has its properties and methods), extended by:

* attached
* parent

FocusWidget : derived from Widget (so has its properties and methods), extended by:

* ClickListenerCollection
* addClickListener

Button : derived from FocusWidget (so has its properties and methods), extended by:

* getHTML
* setHTML

So through a series of inherited commands, the Panel object is instructed by GWT to deliver its HTML. Before delivering its own html, it instructs its children objects to deliver their html. Before their delivery, they also ask their children. And so on, until there are no unpolled children. In this way, the panel's html incorporates all the required html for all of its children.

So as a programmer, all you need to do is to slap down some panels, add some widgets containing the text, buttons, menu items, response to button clicks etc that you want and save it.

The command to "compile" the program takes all the Java objects you have created in your code, pulls out the required html and programmed actions and creates a final html container with a large amount of Javascript that writes the html you instructed through your Java objects.

far more functional and much more fun.

No comments: