Handler on DOM elements in GWT

前端 未结 1 354
野性不改
野性不改 2020-12-10 13:28

I want to add the handler on the buttonelement and i have implemented it as follow. Please help me in resolving the error in this code. I do not want to add handler directly

相关标签:
1条回答
  • 2020-12-10 14:01

    Your code is correct, you might added widget after sink event. you have to add widget before sink event. just example:

    Button  button=new Button("Click");
        Element buttonElement = button.getElement();
          RootPanel.get().add(button);
        Event.sinkEvents(buttonElement, Event.ONCLICK);
        Event.setEventListener(buttonElement, new EventListener() {
    
            @Override
            public void onBrowserEvent(Event event) {
                System.out.println("ok");
                 if(Event.ONCLICK == event.getTypeInt()) {
                     Window.alert("ok");
                      System.out.println("CLICK");
                 }
    
            }
        });
    
    0 讨论(0)
提交回复
热议问题