Pages

Google+ Followers

Wednesday, August 8, 2012

MGWT - A very simple example - click the button

MGWT

MGWT stands for developing mobile applications with GWT and mgwt.
Mgwt works on all kind of mobile devices that support webkit (like iPhone, iPad, iPod, Android, Blackberry, ...)
  • Native support for touchevent the GWT Way
  • Animations built in with GWT MVP
  • lots and lots of widgets
  • specific theme for each plattform (iOS, Android, ...)

 Let' se a simple example starting from a Google Web Toolkit(GWT) project:

1. Create a GWT project
2. In your gwt xml file add this line:
   <inherits name='com.googlecode.mgwt.MGWT'/>

3. Add the MGWT library to your project
(It can be downloaded from: http://www.m-gwt.com/ )

4. And your EntryPoint will be this:


public class mobileEntryPoint implements EntryPoint {

    //global variables
    int countI;
    MTextBox lbl;
   
    public void onModuleLoad() {
                //initialization
                lbl = new MTextBox();
                countI=0;
       
                //set viewport and other settings for mobile
                MGWT.applySettings(MGWTSettings.getAppSetting());
                //build animation helper and attach it
                AnimationHelper animationHelper = new AnimationHelper();
                RootPanel.get().add(animationHelper);

                //build some UI
                LayoutPanel layoutPanel = new LayoutPanel();
                Button button = new Button("Hello User!");               
                //for click event
                button.addTapHandler(new TapHandler() {
                    @Override
                    public void onTap(TapEvent event) {
                        countI++;                                               
                        lbl.setText("You clicked: "+countI+" times");
                    }                   
                }) ;                                                                                             
                layoutPanel.add(button);
                layoutPanel.add(lbl);

                //animate at click
                animationHelper.goTo(layoutPanel, Animation.SLIDE);              
    }
}

By using gwt-phonegap and mgwt you can write applications that can be deployed into the app store or the market place with GWT.