Hi all.

I was working with some GWT widgets, and found that Hyperlink and
Button are some of the most commonly used ones. However, I am not
sure
as to what is the standard (and better !!) paradigm, to define the
"onClick" methods for these widgets.


Following are some of the possibilities :


1. Instantiate a button in a manner (as given at
   http://google-web-
   toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/
ui/Button.html


    
///////////////////////////////////////////////////////////////////////////­//
START
    Button b = new Button("Jump!", new ClickListener() {
      public void onClick(Widget sender) {
        Window.alert("How high?");
      }
    });
   
///////////////////////////////////////////////////////////////////////////­//
END


2. Add clickListener separately.


    
///////////////////////////////////////////////////////////////////////////­//
START
    Button b = new Button("Jump!");


    b.addClickListener
(referenceOfClassImplementingClickListenerInterface);


    
///////////////////////////////////////////////////////////////////////////­//
END


   Note that in this case,
"referenceOfClassImplementingClickListenerInterface" may be of any
type (a widget wrapping "b"; a page wrapping "b"; a module wrapping
"b").


3. Extend "Button", as in :


   
///////////////////////////////////////////////////////////////////////////­//
START
    public abstract class EButton extends Button implements
ClickListener{


                public EButton(){
                addClickListener(this);
        }


        public abstract void onClick(Widget sender);


    }
   
///////////////////////////////////////////////////////////////////////////­//
END


  which may then be used as  ::


  ///////////////////////////////////////////////////////////////////////////­//
START
                                EButton buttonForActionOne = new
EButton(){


                        @Override
                        public void onClick(Widget sender) {
                                Window.alert("In One");


                        }
                };


                EButton buttonForActionTwo = new EButton(){


                        @Override
                        public void onClick(Widget sender) {
                                Window.alert("In Two");


                        }
                };
  ///////////////////////////////////////////////////////////////////////////­//
END


In this case, instantiating a new reference for EButton, "forces" the
user to define its "action-on-click" there and then. Also, this also
binds the widget and the "action-on-click" in a cohesive unit, as
Ebutton is a clickListener to itself.


Thus, I will be grateful if some help could be provided in figuring
out what seems to be the most-preferred way to define the "action-on-
click" for widgets like Button and Hyperlink ..


Looking forward to replies.


Ajay Garg


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to