Extending the .NET Class in Java and Wrapping .NET Methods

Extending the .NET Class in Java and Wrapping .NET Methods

You can extend any .NET class by extending the Java class with the “NObject” type and then call the constructor base constructor by passing the name of the .NET type and arguments for its constructor as an argument.

Example

Here’s an example of how to extend the.NET System.Windows.Forms.Form class and wrap the ShowDialog method.

public class MyExtendedForm extends NObject {

	public MyExtendedForm() throws JavonetException
	{
		super("System.Windows.Forms.Form");
	}

	public void ShowDialog() throws JavonetException
	{
		this.invoke("ShowDialog");
	}
}

See Live Example!