SourceForge Logo

West of j : WUI : The One minute tutorial

In this example, we set out to create the following trivial app:

First, let's create a form and place a couple of input fields in it:

WContainer form = new WContainer(new WGridLayout(2, 0));
form.add(new WLabel("String 1"));
form.add(new WLabel("String 2"));

We'll need another widget to display the result:

private WLabel concat = new WLabel("");

Now, let's add the 'Concat' button:

WButton button = new WButton("Concat");

Right now, if you try to run the application, it will do nothing, simply repaint the page when you click 'Concat'.
We need to add an event handler to the button:

button.addActionListener(new WActionListener() {
 public void actionPerformed(WActionEvent event) {
  concat.setText(input1.getText() + input2.getText());

There's nothing more to it. No JSP, no HTML, the application posts the page back to itself and handles the HTML form perfectly, yet your code looks like GUI code you'd write with a 4GL or the Swing API.

Learn more .