com.google.gwt.sample.stockwatcher.client.ChatWidget.java Source code

Java tutorial

Introduction

Here is the source code for com.google.gwt.sample.stockwatcher.client.ChatWidget.java

Source

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

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

import javax.inject.Inject;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;

public class ChatWidget extends Composite {
    // The @UiField annotation tags elements that the widget should
    // maintain references too.
    @UiField
    Button sendButton;
    @UiField
    DivElement chatLog;

    @Inject
    ChatWidget() {
        initWidget(binder.createAndBindUi(this));
    }

    @UiHandler("sendButton")
    void handleSendClick(ClickEvent event) {
        Window.alert("Hello UI");
        // send message...
    }

    public void appendMessage(String message) {
        chatLog.setInnerText(chatLog.getInnerText() + message);
    }

    private static final Binder binder = GWT.create(Binder.class);

    interface Binder extends UiBinder<Widget, ChatWidget> {
    }
}