Pages

Saturday, October 24, 2009

Google web toolkit animations

This is my first animation program in GWT. It is very simple. Here just one button will move diagonally on an absolute panel. Two classes are involved here.Please check in.


Here is the first Main Entry point of the GWT app




public class MainEntryPoint implements EntryPoint {

AbsolutePanel abPanel = new AbsolutePanel();
Button button = new Button("Click Me");
DemoAnim demoAnim = new DemoAnim(abPanel, button);

public MainEntryPoint() {
}

public void onModuleLoad() {

    abPanel.setSize("250px", "250px");
    abPanel.add(button);

    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            demoAnim.run(2000);
            }
    });
    RootPanel.get().add(abPanel);
}
}


Now here is the DemoAnimation class. This class will control the absolute panel and the button of the main class.



public class DemoAnim extends Animation{

    AbsolutePanel abPanel;
    Button button;

    int counter = 0;
    public DemoAnim(AbsolutePanel abPanel, Button button) {
        this.abPanel = abPanel;
        this.button = button;
        abPanel.add(button);
        abPanel.setWidgetPosition(button, 0, 0);

    }


    @Override
    protected void onUpdate(double progress) {
        counter ++;
        abPanel.setWidgetPosition(button, counter, counter);
    }

    @Override
    protected void onComplete() {
        super.onComplete();
        counter = 0;

    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onCancel() {
        super.onCancel();
    }

}


Here is the showcase demo of GWT animations

No comments:

Post a Comment