tags:

views:

291

answers:

2

I want to use NetBeans to build the GUI for my project, but implement the functionality using C code. Is there any way I can make the C code run when a button in the GUI is clicked?

+1  A: 

I believe you can use standard JNI with netbeans.

Here's a link for version 6.0, (http://www.netbeans.org/kb/60/cnd/beginning-jni-linux.html) which I hope still applies for 6.5.

Once you set up a basic JNI C-library with the appropriate headers, it's pretty easy to use from the java side. And once you have that much done, it's even possible to throw Java Exceptions from the C code (http://www.codeproject.com/KB/debug/jni_ex.aspx)

But you should take note that if you're sending a lot of data back and forth, the overhead of the JNI data passing could be greater than the gain of using C for your speed-critical sections.

Cheers

Marc
+1: Netbeans was happy to support a project with a mix of JNI and Java more than a year ago, at least. I had some issues getting ANT to want to understand the dependency relationships at the Java-C boundary that took a while to straighten out. Not having used ANT before starting that project was 85% or more of my problem, however.
RBerteig
A: 

You could use Java Native Access (JNA), a new technology. With JNA, Java applications can dynamically access native libraries from Java without JNI. JNA allows you to call directly into native functions using natural Java method invocation.

The project home page is here:

https://jna.dev.java.net/

Wikimedia article:

http://en.wikipedia.org/wiki/Java_Native_Access

mjustin