litesoft
@ 948
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package org.litesoft.sandbox.csapp.client; import org.litesoft.sandbox.csapp.client.widgets.*; import com.google.gwt.core.client.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.rpc.*; import com.google.gwt.user.client.ui.*; /** * Entry point classes define <code>onModuleLoad()</code> */ public class CSapp implements EntryPoint { @Override public void onModuleLoad() { final Button button = new Button( "Click me" ); final Label label = new Label(); button.addClickHandler( new ClickHandler() { @Override public void onClick( ClickEvent event ) { if ( label.getText().equals( "" ) ) { CSappService.Async.INSTANCE.getMessage( "Hello, World!", new MyAsyncCallback( label ) ); } else { label.setText( "" ); } } } ); // Assume that the host HTML has elements defined whose // IDs are "slot1", "slot2". In a real app, you probably would not want // to hard-code IDs. Instead, you could, for example, search for all // elements with a particular CSS class and replace them with widgets. // RootPanel.get( "slot1" ).add( button ); RootPanel.get( "slot2" ).add( label ); RootPanel.get( "slot3" ).add( new MyPanel() ); } private static class MyAsyncCallback implements AsyncCallback<String> { private Label label; public MyAsyncCallback( Label label ) { this.label = label; } @Override public void onSuccess( String result ) { label.getElement().setInnerHTML( result ); } @Override public void onFailure( Throwable throwable ) { label.setText( "Failed to receive answer from server!" ); } } } |