On 28 sep, 20:34, YoeZ <[EMAIL PROTECTED]> wrote:
> Hi,
> How can I access event from another widget?
> Or I want to implement an event from another widget.
> let say I have a three class:
> iCombo.java = contain listbox
> ComboParent.java = contain iCombo class
> MainMenu.java = contain ComboParent
>
> in the MainMenu.java class, I want to implement the event when the
> listbox (in iCombo class) has changed.

iCombo has to fire events on listbox's change event; and ComboParent
has to fire events on iCombo's event; then MainMenu can register as a
listener to the ComboParent instance.

> /****************
> * iCombo.java
> ****************/
> public class iCombo extends Composite implements ChangeListener {

The goal of a Composite is to mask the internal implementation
(encapsulation) and expose its own API. It doesn't matter to iCombo
users that it's made of three ListBoxes or a set or RadioButtons or
whatever other widget; what matters is that some events are fired in
response to changes (generally in response to user interaction).

(note: I wouldn't implement ChangeListener on iCombo, it's an
"implementation detail"; I would rather have a ChangeListener stored
in a private field: private ChangeListener listener = new
ChangeListener() { ... }; )

iCombo should implement SourcesChangeEvents:

private ChangeListenerCollection listeners = new
ChangeListenerCollection();

public void addChangeListener(ChangeListener listener) {
   listeners.add(listener);
}
public void removeChangeListener(ChangeListener listener) {
   listeners.remove(listener);
}

>     private HorizontalPanel hPanel = new HorizontalPanel();
>     private ListBox ListA = new ListBox();
>     private ListBox ListB = new ListBox();
>     private ListBox ListC = new ListBox();
>
>     public iCombo () {
>         hPanel.add(ListA);
>         hPanel.add(ListB);
>         hPanel.add(ListC);
>
>         ListA.addChangeListener(this);
>         ListB.addChangeListener(this);
>         ListC.addChangeListener(this);
>
>         initWidget(hPanel);
>     }
>     public void onChange(Widget sender) {
>         // I want to implement this method from another class? :(

   listeners.fireChange(this);

>     }
>
> }
>
> /****************
> * ComboParent.java
> ****************/
> public class ComboParent extends Composite {

Same here.

> /****************
> * MainMenu.java
> ****************/
> public class MainMenu implements EntryPoint {
>     private VerticalPanel vPanel = new VerticalPanel();
>     private ComboParent cp = new ComboParent ();
>
>     public void onModuleLoad() {
>         vPanel.add(cp);
>
>         RootPanel.get().add(cp);

    cp.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            // ComboParent fired a change event.
        }
    });

>     }
>
>     // How do I know when the ListBox has Changed From here..
>
> }
--~--~---------~--~----~------------~-------~--~----~
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