Patrick Shea <[email protected]> wrote:

Unfortunately I don't come from an html background. I'm just trying to reuse the same listener for more than one component but I can't because I can't separate which is which!

If you define your components in WTKX such as this:

<PushButton wtkx:id="button1" .../>
<PushButton wtkx:id="button2" .../>

then let Pivot inject the buttons into your controller class:

class Controller {
  @WTKX(id="button1") PushButton button1;
  @WTKX(id="button2") PushButton button2;

  public void createGui() {
    WTKXSerializer serializer = new WTKXSerializer();
    Component topLevelComponent = serializer.readObject(this, "gui.wtkx");
    serializer.bind(this);
    // reuse the same listener for both buttons
    ButtonPressListener listener = new MyButtonPressListener();
    button1.getButtonPressListeners().add(listener);
    button2.getButtonPressListeners().add(listener);
    // ... show topLevelComponent etc.
  }

  // your listener can decide which is which
  private class MyButtonPressListener implements ButtonPressListener {
    public void buttonPressed(Button button) {
      if(button == button1) {
        ...
      } else if(button == button2) {
        ...
      }
    }
  }
}

Regards,
Dirk.



Reply via email to