I included a second JFrame in NetBeans, which I used as a child window. When the child window was closed, all windows were closed. I finally figured out that the default close operation needed to be either HIDE_ON_CLOSE or DISPOSE_ON_CLOSE. The default in Java is HIDE_ON_CLOSE, but in NetBeans is EXIT_ON_CLOSE. I first changed this [...]
Archives for February 2007
Link to Random Image Password Generation
Captchas.net
Reducing redundant code by wrapping JNI functions.
My HelloWorldNative.c, with the “nativePrintObject” function reduced by wrapping the object and integer field retrieval: JNIEXPORT void JNICALL Java_helloworld_Main_nativePrintObject(JNIEnv *env, jobject ths, jobject wsv){ jint ipAddress; jstring jPageVisited; char *pageVisited; jstring jRefererURL; char *refererURL; jobject ipObject; ipAddress = getIntegerField(env, wsv, “ipAddress”); printf(” wsv.ipAddress = %d.%d.%d.%d\n”, ( ipAddress & 0xff000000 ) >> 24, ( ipAddress & [...]
Passing an object including java Objects to a C library.
Very similar to including Java Strings:The passed object, WebSiteVisit: package helloworld; /**** @author thomas*/public class WebSiteVisit { /** URL of the web page that linked user to this one */ public String refererURL; public String pageVisited; public int ipAddress; IPAddress ipAddr; /** Creates a new instance of WebSiteVisit */ public WebSiteVisit() { } public WebSiteVisit(String [...]
Passing an object including java Strings to a C library using JNI.
Main.java, the class which calls the C function, passing the WebSiteVisit object /**** @author thomas*/public class Main { private native void nativePrintObject(WebSiteVisit wsv);/** Creates a new instance of Main */public Main() {} static { System.load(“/home/thomas/testlib/HelloWorldNative/dist/HelloWorldNative.so”);}/** * @param args the command line arguments */public static void main(String[] args) { Main me = new Main(); WebSiteVisit a, [...]
Passing an object including java Strings to a C library.
Main.java, the class which calls the C function, passing the WebSiteVisit object /**** @author thomas*/public class Main { private native void nativePrintObject(WebSiteVisit wsv); /** Creates a new instance of Main */ public Main() { } static { System.load(“/home/thomas/testlib/HelloWorldNative/dist/HelloWorldNative.so”); } /** * @param args the command line arguments */ public static void main(String[] args) { Main [...]
Java Native Interface – setting and retrieving object fields
My reference: Java Native Interface This table was specifically handy: Java Type JNI Type machine dependentC/C++ typedef Signature Call…MethodGet…Field boolean jboolean unsigned char Z Boolean byte jbyte signed char B Byte char jchar unsigned short C Char short jshort short S Short int jint int I Int long jlong long J Long float jfloat float [...]
JNI Types and Data Structures
Attempting to continue from experiments begun here. JNI Types and Data Structures
Using Native Data Structures in JNI
Write Efficient Java Apps Using Native Data Structures with JNI
Linking a static library to Java using JNI
Beginning JNI Linux tutorial for Netbeans Once I had accomplished the above with complete success, I extended the experiment by linking my static library (.a) to the dynamic library, and calling the static library function from the dynamic library function. My HelloWorldNative.h:/* DO NOT EDIT THIS FILE – it is machine generated */#include <jni.h>/* Header [...]
Posts