public class Handler implements ClickHandler {
    private TextBox textBox = null;

    public Handler(TextBox textBox ) {
         this.textBox = textBox;
    }

    ....
}


Jim
http://www.gwtorm.com - GWT ORM
http://code.google.com/p/dreamsource-orm/


On May 21, 11:18 am, Dalla <dalla_man...@hotmail.com> wrote:
> I suppose this would work great if I actually clicked the textbox.
> But I want to change the text in the textbox when I click a button,
> not the textbox itself :-)
>
> On 21 Maj, 16:36, Jim <jim.p...@gmail.com> wrote:
>
>
>
> > public class Handler implements ClickHandler {
> >         @Override
> >         public void onClick(ClickEvent event) {
> >              Widget widget = event.getSource();
> >              if (widget instanceof TextBox) {
> >                   TextBox textBox = (TextBox)widget;
> >                   //do whatever you want
> >                   //If you have many TextBox, you can use Id to
> > identify them
> >              }
> >              else {//some other widget that fires the same event
>
> >              }
> >         }
>
> > }
>
> > Jimhttp://www.gwtorm.com-GWT ORM
>
> > On May 21, 9:43 am, Dalla <dalla_man...@hotmail.com> wrote:
>
> > > Yes, this I know. In this example the source would be the sendButton,
> > > right?
> > > But is there any way in which I can manipulate helloField when Handler
> > > is a separate class?
> > > Or do I have to make Handler an inner class inside EventManagerTest to
> > > be able to manipulate helloField?
>
> > > On 21 Maj, 15:35, Jim <jim.p...@gmail.com> wrote:
>
> > > > Using GwtEvent.getSource() retrieves the source that last fired this
> > > > event so you can differentiate event source widgets.
>
> > > > Jimhttp://www.gwtorm.com-GWTORM
>
> > > > On May 21, 4:44 am, Dalla <dalla_man...@hotmail.com> wrote:
>
> > > > > I guess this question is not really GWT specific, but I haven´t been
> > > > > working much with handlers at all when developing web applications
> > > > > earlier.
>
> > > > > I´ll make a very simple example:
>
> > > > > public class EventManagerTest implements EntryPoint {
>
> > > > >         public void onModuleLoad() {
> > > > >                 final Button sendButton = new Button("Send");
> > > > >                 final TextBox helloField = new TextBox();
> > > > >         }
>
> > > > > }
>
> > > > > Let´s say I want to print "Hello world" in the textbox when someone
> > > > > clicks sendButton.
> > > > > Most examples would use:
>
> > > > >         sendButton.addClickHandler(new ClickHandler() {
> > > > >                 public void onClick(ClickEvent event) {
> > > > >                         helloField.setText("Hello world");
> > > > >                 }
> > > > >         });
>
> > > > > But if my application will handle multiple click event, I read that it
> > > > > would be better to create a separate class to handle the events,
> > > > > something like:
>
> > > > > public class Handler implements ClickHandler {
>
> > > > >         @Override
> > > > >         public void onClick(ClickEvent event) {
> > > > >         }
>
> > > > > }
>
> > > > > Now to my question: How can I set the text of the helloField (or
> > > > > manipulate any other widget for that matter)
> > > > > from my Handler class, when the helloField is in another class? Or did
> > > > > I get this wrong altogether?- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to