2 Replies Latest reply on May 3, 2012 11:14 AM by 931470

    Call event from another event

    931470
      I have a button where i need to call one event from another... does anyone have any ideas on what the syntax would be?

      public class PushButton extends Button
      {
      public PushButton()
      {
      /*
      * Mouse Pressed Event
      */
      this.addEventHandler(MouseEvent.MOUSE_PRESSED,
      new EventHandler<MouseEvent>() {

      @Override
      public void handle(MouseEvent e) {

      System.out.println("MousePressed");

      };
      });


      /*
      * Mouse Released Event
      */
      this.addEventHandler(MouseEvent.MOUSE_RELEASED,
      new EventHandler<MouseEvent>() {

      @Override
      public void handle(MouseEvent e) {

      System.out.println("MouseReleased");
                
                *// Make a call to the mouse pressed event????*
      };
      });
      }
      }
        • 1. Re: Call event from another event
          Sai Pradeep Dandem
          Hi,
          As per your requirement, i hope the below code should work. :)
          public class PushButton extends Button
          {
               public PushButton()
               {
                    
                    /*
                     * Mouse Pressed Event
                     */
                    final EventHandler<MouseEvent> mousePressedEvent = new EventHandler<MouseEvent>() {
                         @Override
                         public void handle(MouseEvent e) {
                              System.out.println("MousePressed");
                         };
                    };
                    this.addEventHandler(MouseEvent.MOUSE_PRESSED, mousePressedEvent);
          
                    /*
                     * Mouse Released Event
                     */
                    this.addEventHandler(MouseEvent.MOUSE_RELEASED,
                              new EventHandler<MouseEvent>() {
          
                         @Override
                         public void handle(MouseEvent e) {
                              System.out.println("MouseReleased");
                              // Make a call to the mouse pressed event
                              mousePressedEvent.handle(e);
                         };
                    });
               }
          }
          Happy Coding !! :)

          Regards,
          Sai Pradeep Dandem.
          1 person found this helpful
          • 2. Re: Call event from another event
            931470
            Thanks for your help once again,this has let me progress :)