I think there is a simpler way to do this for example if you modify
you code iCombo.java to be abstract
/****************
* iCombo.java
****************/
public abstract class iCombo extends Composite implements
SourcesChangeEvents
{
private HorizontalPanel hPanel = new HorizontalPanel();
private ListBox ListA = new ListBox();
private ListBox ListB = new ListBox();
private ListBox ListC = new ListBox();
private ChangeListenerCollection listeners = new
ChangeListenerCollection();
public abstract void manageAllListeners( ListBox listBox); // you
need to have this method that will manage your listener in this class
public iCombo () {
hPanel.add(ListA);
hPanel.add(ListB);
hPanel.add(ListC);
FillList();
ListA.addChangeListener(new ChangeListener() {
public void onChange(Widget arg0) {
// listeners.fireChange(ListA);
manageAllListeners( ListA); // use this
}
});
ListB.addChangeListener(new ChangeListener() {
public void onChange(Widget arg0) {
manageAllListeners( ListB);
}
});
ListC.addChangeListener(new ChangeListener() {
public void onChange(Widget arg0) {
manageAllListeners( ListC);
}
});
initWidget(hPanel);
}
private void FillList() {
ListA.clear();
ListA.addItem("ListA1");
ListA.addItem("ListA2");
ListA.addItem("ListA3");
ListB.clear();
ListB.addItem("ListB1");
ListB.addItem("ListB2");
ListB.addItem("ListB3");
ListC.clear();
ListC.addItem("ListC1");
ListC.addItem("ListC2");
ListC.addItem("ListC3");
}
public void addChangeListener(ChangeListener listener) {
listeners.add(listener);
}
public void removeChangeListener(ChangeListener listener) {
listeners.remove(listener);
}
}
now in the ComboParent when you try to create an instance of iCombo
it will ask you to add unimplemanted method ..see the example
/****************
* ComboParent.java
****************/
public class ComboParent extends Composite {
private VerticalPanel vPanel = new VerticalPanel();
private iCombo MyCombo = new iCombo(){
public void manageAllListeners( ListBox listBox){
// here you can add what you want
}
};
private Button btn1 = new Button("OK");
private TextBox txt1 = new TextBox();
public ComboParent() {
vPanel.add(txt1);
vPanel.add(MyCombo);
vPanel.add(btn1);
initWidget(vPanel);
}
}
in the same way you can go through the other class.
hope that will help you .
On Sep 29, 4:27 pm, YoeZ <[EMAIL PROTECTED]> wrote:
> Thank you very much, thomas
> here's the final sample code and it really works... :)
>
> but the problem is, in the MainMenu, I don't know which listbox that
> send the listener.
> in the MainMenu, I provide three textboxes
> txtListA = catch the event from listA
> txtListB = catch the event from listB
> txtListC = catch the event from listC
> so, I have to know first, the name of the sender widget, (which is
> listA? listB? or listC?)
> then set the txtListA.setText(listA); and so on
>
> I have no idea, how to get the sender name.
> I have tried sender.getclass().getname() but the result is not what I
> want.
>
> please help me (again) ;)
>
> best regards
>
> /****************
> * iCombo.java
> ****************/
> public class iCombo extends Composite implements SourcesChangeEvents
> {
> private HorizontalPanel hPanel = new HorizontalPanel();
> private ListBox ListA = new ListBox();
> private ListBox ListB = new ListBox();
> private ListBox ListC = new ListBox();
> private ChangeListenerCollection listeners = new
> ChangeListenerCollection();
>
> public iCombo () {
> hPanel.add(ListA);
> hPanel.add(ListB);
> hPanel.add(ListC);
>
> FillList();
>
> ListA.addChangeListener(new ChangeListener() {
> public void onChange(Widget arg0) {
> listeners.fireChange(ListA);
> }
> });
> ListB.addChangeListener(new ChangeListener() {
> public void onChange(Widget arg0) {
> listeners.fireChange(ListB);
> }
> });
> ListC.addChangeListener(new ChangeListener() {
> public void onChange(Widget arg0) {
> listeners.fireChange(ListC);
> }
> });
>
> initWidget(hPanel);
> }
>
> private void FillList() {
> ListA.clear();
> ListA.addItem("ListA1");
> ListA.addItem("ListA2");
> ListA.addItem("ListA3");
> ListB.clear();
> ListB.addItem("ListB1");
> ListB.addItem("ListB2");
> ListB.addItem("ListB3");
> ListC.clear();
> ListC.addItem("ListC1");
> ListC.addItem("ListC2");
> ListC.addItem("ListC3");
> }
>
> public void addChangeListener(ChangeListener listener) {
> listeners.add(listener);
> }
>
> public void removeChangeListener(ChangeListener listener) {
> listeners.remove(listener);
> }
>
> }
>
> /****************
> * iComboParent.java
> ****************/
> public class iComboParent extends Composite implements
> SourcesChangeEvents {
> private HorizontalPanel vPanel = new HorizontalPanel();
> private iCombo MyCombo = new iCombo();
> private Button btn1 = new Button("OK");
> private ChangeListenerCollection listeners = new
> ChangeListenerCollection();
>
> public iComboParent() {
> vPanel.add(MyCombo);
> vPanel.add(btn1);
>
> initWidget(vPanel);
>
> MyCombo.addChangeListener(new ChangeListener() {
> public void onChange(Widget sender) {
> listeners.fireChange(sender);
> }
> });
>
> }
>
> public void addChangeListener(ChangeListener listener) {
> listeners.add(listener);
> }
>
> public void removeChangeListener(ChangeListener listener) {
> listeners.remove(listener);
> }
>
> }
>
> /****************
> * MainMenu.java
> ****************/
> public class MainMenu implements EntryPoint {
> private VerticalPanel vPanel = new VerticalPanel();
> private TextBox txtListA = new TextBox();
> private TextBox txtListB = new TextBox();
> private TextBox txtListC = new TextBox();
> private ComboParent cp = new ComboParent ();
>
> public void onModuleLoad() {
> vPanel.add(txtListA);
> vPanel.add(txtListB);
> vPanel.add(txtListC);
> vPanel.add(cp);
>
> cp.addChangeListener(new ChangeListener() {
> public void onChange(Widget sender) {
> ListBox lb = (ListBox) sender;
>
> txtListA.setText(lb.getItemText(lb.getSelectedIndex()));
> }
> });
>
> RootPanel.get().add(vPanel);
> }
>
> }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---