4 Replies Latest reply: May 6, 2014 9:19 AM by gimbal2 RSS

    How to use Event Listeners in java?

    7d842125-81b7-4ac4-968d-3bb4f4b96089

      hi could anyone explain me about how the event Listeners work in java,To get the data based on the event occurs in outside the application.

      I have this method in one of my API class I am not understanding how this methods are going to work.

       

      public interface SBXPCXMLEventListener {
        
      public void OnReceiveEventXML(String eventXML);
        
      }
        
      private static List<SBXPCXMLEventListener> listenerList = new ArrayList<SBXPCXMLEventListener>();



        
      protected static void fireXMLEvent(String xml) {
        
      Iterator<SBXPCXMLEventListener> iter = listenerList.iterator();
        
      while (iter.hasNext()) {
        iter
      .next().OnReceiveEventXML(xml);
        
      }
        
      }

        
      public static void addXMLListener(SBXPCXMLEventListener listener) {
        listenerList
      .add(listener);
        
      }

        
      public static Object removeXMLListener(SBXPCXMLEventListener listener) {
        
      return listenerList.remove(listener);
        
      }


      i have done like this.This is used to capture the events from the fingerprint machine when run this class I am not getting any data from the machine when i did thumb impression in the machine.


      public class EventListnere implements SBXPCXMLEventListener {

       

          public static void main(String[] args) {

              boolean flag = SBXPCProxy.ConnectTcpip(1, "10.0.0.8", 5005, 1234);

              System.out.println("flag = " + flag);

      //        SBXPCProxy.st

      //        System.out.println("before "+System.currentTimeMillis());

              boolean flag1 = SBXPCProxy.StartEventCapture(1, 1, 1);

              EventListnere el = new EventListnere();

              SBXPCProxy.addXMLListener(el);

          }

       

          @Override

          public void OnReceiveEventXML(String eventXML) {

              System.out.println("eventXML = " + eventXML);

          }

      }