Click here to Skip to main content
15,881,380 members
Articles / Programming Languages / Java / Java SE

Example of using Object-Oriented Java Native Interface in C++

Rate me:
Please Sign up or sign in to vote.
3.73/5 (10 votes)
3 Feb 2006CPOL4 min read 78.3K   1.8K   39  
Demonstrates an easy way of creating and embedding Java objects into C++ code, with Object-Oriented JNI.
/**************************************************************************
 *
 * The code is generated for Microsoft VC++ 6.0
 *
 * with OOJNI Demo Tool developed by Vitaly Shelest (Javain Ltd.)
 *
 * You may use the code generated with OOJNI Demo only
 *
 * for evaluation and any use other than evaluation
 *
 * requiers a purchase of a license.
 *
 * Do not change the content of this file.
 *
 * You can order the latest version of OOJNI Add-in at http://www.javain.com
 * 
 **************************************************************************/

#include "stdafx.h"
#include "defproxies.h"

const char* CPP_Java_Bridge::java::awt::ColorJNIProxy::_clazzName = "java/awt/Color";

void CPP_Java_Bridge::java::awt::ColorJNIProxy::Color_init(){
    blue_ID = 0;
}

CPP_Java_Bridge::java::awt::Color CPP_Java_Bridge::java::awt::ColorJNIProxy::get_blue() {
    try{
        CPP_Java_Bridge::java::awt::Color result;
        jclass clazz = ::jni_helpers::_simple_class_loader::getClass(_clazzName);
        if(clazz == 0)
            clazz = reinterpret_cast<jclass> (::jni_helpers::JNIEnvHelper::FindClass(_clazzName));
        jfieldID blue_ID = ::jni_helpers::JNIEnvHelper::GetStaticFieldID(clazz, "blue", "Ljava/awt/Color;");
        jobject tmpobject = ::jni_helpers::JNIEnvHelper::GetStaticObjectField(clazz, blue_ID);
        result = tmpobject;
        if(tmpobject)
            ::jni_helpers::JNIEnvHelper::DeleteLocalRef(tmpobject);
        if(clazz != 0)
            ::jni_helpers::JNIEnvHelper::DeleteLocalRef(clazz);
        return result;
    }catch(::jni_helpers::JVMException e){
        throw ::jni_helpers::JVMException(jni_helpers::CSmartString("CPP_Java_Bridge::java::awt::ColorJNIProxy::get_blue:\n") + e.getMessage());
    }catch(...){
        throw ::jni_helpers::JVMException("CPP_Java_Bridge::java::awt::ColorJNIProxy::get_blue: System Error");
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Javain Ltd
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions