>
1. Getting started
2. Calling methods
3. Working with .NET Objects
4. Fields and Properties
5. Methods Arguments
6. Nested Types
7. Enums
8. Arrays and Collections
9. Embeding UI controls
10. Referencing libraries
11. Off-line activation
12. Events and Delegates
13. Disposing and Garabage Collection
14. .NET Configuration Files (AppConfig, WebConfig)
15. Exceptions, Debugging and Testing
16. Strongly-Typed Wrappers
    17. Advanced Activation and Licensing
    18 Other usage scenarios

      Subscribing to .NET Events

      Subscribe to any .NET event with Javonet. Event subscription works the same way as listening Java events. The performance of event subscription is extremely high and allows you to interact with .NET code like it was native Java code. When the event occurs, your Java listener callback is called in a separate thread.

      The simplest way to subscribe an event is to use an anonymous Java class.

      Example

      To create a .NET button and listen for a “Click” event:

        NObject button = Javonet.New("System.Windows.Forms.Button");
        button.set("Text", "Click me!");
      
        button.addEventListener("Click",new INEventListener() {
          public void eventOccurred(Object[] arguments) {
            System.out.println(".NET event occured");
          }
        });

      The anonymous class should implement special INEventListener interface. Alternatively you can write a separate class as the event listener by extending NEventListener and overriding the eventOccurred method, or by implementing the INEventListener interface.

      //Your custom Java listener class for .NET events
      
        public class MyEventListener implements INEventListener
        {
          @Override
          public void eventOccurred(Object[] arguments) {
            System.out.println(".NET Event Occurred");
          }
      
        }
      
      //Usage of your listener class
      
        NObject button = Javonet.New("System.Windows.Forms.Button");
        button.set("Text", "Click me!");
      
        MyEventListener listener = new MyEventListener();
        button.addEventListener("Click",listener);

      See Live Example!

      Similiar Articles