litesoft
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package org.sample.client;
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 MyGwtApplication implements EntryPoint
{
protected DialogBox mDialogBox;
protected MyServiceAsync mSvc;
protected AsyncCallback<String> mCallback;
/**
* This is the entry point method.
*/
public void onModuleLoad()
{
// define the service you want to call
mSvc = (MyServiceAsync) GWT.create( MyService.class );
ServiceDefTarget endpoint = (ServiceDefTarget) mSvc;
endpoint.setServiceEntryPoint( "MyService" );
// define a handler for what to do when the
// service returns a result
mCallback = new AsyncCallback<String>()
{
public void onSuccess( String result )
{
serverAnswered( result );
}
public void onFailure( Throwable ex )
{
RootPanel.get().add( new HTML( ex.toString() ) );
}
};
Image img = new Image( "http://code.google.com/webtoolkit/logo-185x175.png" );
Button button = new Button( "Click me" );
// We can add style names
button.addStyleName( "pc-template-btn" );
// or we can set an id on a specific element for styling
img.getElement().setId( "pc-template-img" );
VerticalPanel vPanel = new VerticalPanel();
vPanel.setWidth( "100%" );
vPanel.setHorizontalAlignment( VerticalPanel.ALIGN_CENTER );
vPanel.add( img );
vPanel.add( button );
// Add image and button to the RootPanel
RootPanel.get().add( vPanel );
// Create the dialog box
mDialogBox = new DialogBox();
// dialogBox.setText("Welcome to GWT!");
mDialogBox.setAnimationEnabled( true );
Button closeButton = new Button( "close" );
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.setWidth( "100%" );
dialogVPanel.setHorizontalAlignment( VerticalPanel.ALIGN_CENTER );
dialogVPanel.add( closeButton );
closeButton.addClickHandler( new ClickHandler()
{
public void onClick( ClickEvent event )
{
mDialogBox.hide();
}
} );
// Set the contents of the Widget
mDialogBox.setWidget( dialogVPanel );
button.addClickHandler( new ClickHandler()
{
public void onClick( ClickEvent event )
{
mSvc.myMethod( "Do Stuff", mCallback );
}
} );
}
private void serverAnswered( String pText )
{
mDialogBox.setText( pText );
mDialogBox.center();
mDialogBox.show();
}
}
|
Revision |
Author |
Commited |
Message |
162
|
GeorgeS
|
Fri 01 Apr, 2011 19:58:40 +0000 |
|