⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 native_java.html

📁 JNI(java本地接口)之delphi版
💻 HTML
字号:
<html>
<BODY BGCOLOR="#e0e0e0">
<pre class="sourcecode"><code><font color="#003399"><i>/****************************************************************************
 *
 *  Native.java
 *
 *  This code implements the interface to the Delphi code.
 *
 *
*/</i></font>
<b>class</b> <b>Native</b> {

    <font color="#003399"><i>// multiplies 2 integers and returns the result</i></font>
  <b>native</b> <b>public</b> <b>int</b> multiplyIntegers(<b>int</b> op1, <b>int</b> op2);

    <font color="#003399"><i>// initialize an array of bytes with the value 'value'</i></font>
  <b>native</b> <b>public</b> <b>void</b> initializeByteArrayOnce(<b>byte</b>[] array, <b>byte</b> value);

    <font color="#003399"><i>// Initializes an array of elements 'count' times with value 'value'</i></font>
    <font color="#003399"><i>// The native method is actually overloaded to provided the functionality</i></font>
    <font color="#003399"><i>// for the previous method 'initializeByteArrayOnce'. See Native.dpr</i></font>
    <font color="#003399"><i>// for details on how to overload native methods.</i></font>
  <b>native</b> <b>public</b> <b>void</b> initializeByteArray(<b>byte</b>[] array, <b>int</b> count, <b>byte</b> value);

    <font color="#003399"><i>// Used to test the code during upgrade to the JEDI standard</i></font>
  <b>native</b> <b>public</b> <b>void</b> testAllTypesD(<b>boolean</b> bool, <b>byte</b> b, <b>char</b> c, <b>int</b> i, <b>long</b> l, <b>float</b> f, <b>double</b> d);

    <font color="#003399"><i>// Displays the version of the JVM</i></font>
  <b>native</b> <b>public</b> <b>void</b> printVersion();

    <font color="#003399"><i>// guess?</i></font>
  <b>native</b> <b>public</b> <b>void</b> displayHelloWorld();

    <font color="#003399"><i>// Sieves prime numbers</i></font>
  <b>native</b> <b>public</b> <b>static</b> <b>int</b> countPrimes(<b>byte</b>[] abFlags);

    <font color="#003399"><i>// Pass a 2-D array of bytes to be printed and modified</i></font>
  <b>native</b> <b>public</b> <b>void</b> pass2DByteArray(<b>byte</b>[][] array);

    <font color="#003399"><i>// Prints all members of this class by using callbacks to the method</i></font>
    <font color="#003399"><i>// 'toString' below</i></font>
  <b>native</b> <b>public</b> String toStringWithPrint();

    <font color="#003399"><i>// Prints a Java String in native code and returns a Java String</i></font>
  <b>native</b> <b>public</b> String printLine(String text);

    <font color="#003399"><i>// Prints w, x, y, and z using native code (no callback to this class)</i></font>
  <b>native</b> <b>public</b> <b>void</b> printWXYZ();

    <font color="#003399"><i>// Causes an exception, doesn't handle it in native code</i></font>
  <b>native</b> <b>public</b> <b>void</b> causeException();

    <font color="#003399"><i>// Causes an exception, handles it in native code</i></font>
  <b>native</b> <b>public</b> <b>void</b> handleException();

    <font color="#003399"><i>// Prints each element of the objArray using a callback to the object's</i></font>
    <font color="#003399"><i>// 'toString' method</i></font>
  <b>native</b> <b>public</b> <b>void</b> printObjectArray(Object[] objArray, <b>boolean</b> Print);

    <font color="#003399"><i>// Creates, allocates, and initializes an array or Rectangles in native</i></font>
    <font color="#003399"><i>// code and returns the array to Java</i></font>
  <b>native</b> <b>public</b> java.awt.Rectangle[] returnRectArray(<b>int</b> size);

    <font color="#003399"><i>// No arguments, no return value</i></font>
  <b>native</b> <b>public</b> <b>void</b> VoidVoid();

    <font color="#003399"><i>// For timing test of C++ calling back to Java</i></font>
  <b>native</b> <b>public</b> <b>void</b> callbackVoid(<b>int</b> Count);

    <font color="#003399"><i>// Loads the file Native.DLL at run-time</i></font>
  <b>static</b> {
    System.loadLibrary(<font color="#9933CC">&quot;Native&quot;</font>);
  }

    <font color="#003399"><i>// Primitive types, and a string</i></font>
  String string_;
  <b>boolean</b> boolean_;
  <b>byte</b> byte_;
  <b>char</b> char_;
  <b>double</b> double_;
  <b>float</b> float_;
  <b>int</b> int_;
  <b>long</b> long_;
  <b>short</b> short_;

    <font color="#003399"><i>// To test accessing public/private static/non-static</i></font>
  <b>public</b> String w;
  <b>public</b> <b>int</b> x;
  <b>private</b> <b>int</b> y;
  <b>public</b> <b>static</b> <b>int</b> z;

    <font color="#003399"><i>// Constructor</i></font>
  <b>public</b> <b>Native</b>()
  {
    boolean_ = <b>true</b>;
    byte_ = 19;
    char_ = <font color="#9933CC">'A'</font>;
    double_ = 3.1415926535;
    float_ = 10.2f;
    int_ = 123456;
    long_ = 987654321;
    short_ = 12345;
    string_ = <font color="#9933CC">&quot;This is a Java string&quot;</font>;

    w = <font color="#9933CC">&quot;a Native String&quot;</font>;
    x = 5;
    y = 11;
    z = 20;
  }

	<b>public</b> <b>static</b> <b>void</b> printHello()
  {
    System.out.println(<font color="#9933CC">&quot;Hello from Java!&quot;</font>);
  }

    <font color="#003399"><i>// A good thing to have</i></font>
  <b>public</b> String toString()
  {
    String str = <font color="#9933CC">&quot;Native[&quot;</font> +
                 <font color="#9933CC">&quot;x=&quot;</font> + x +
                 <font color="#9933CC">&quot;,y=&quot;</font> + y +
                 <font color="#9933CC">&quot;,boolean_=&quot;</font>  + boolean_ +
                 <font color="#9933CC">&quot;,byte_=&quot;</font> + byte_ +
                 <font color="#9933CC">&quot;,char_=&quot;</font> + char_ +
                 <font color="#9933CC">&quot;,double_=&quot;</font> + double_ +
                 <font color="#9933CC">&quot;,float_=&quot;</font> + float_ +
                 <font color="#9933CC">&quot;,int_=&quot;</font> + int_ +
                 <font color="#9933CC">&quot;,long_=&quot;</font> + long_ +
                 <font color="#9933CC">&quot;,short_=&quot;</font> + short_ +
                 <font color="#9933CC">&quot;,string_=&quot;</font> + string_ +
                 <font color="#9933CC">&quot;]&quot;</font>;

    <b>return</b> str;
  }

  <b>public</b> <b>void</b> voidFunc()
  {
  }

  <b>public</b> <b>void</b> testAllTypes(<b>boolean</b> bool, <b>byte</b> b, <b>char</b> c, <b>int</b> i, <b>long</b> l, <b>float</b> f, <b>double</b> d)
  {
    System.out.println(  <font color="#9933CC">&quot;boolean = &quot;</font> + bool + <font color="#9933CC">&quot;, &quot;</font>
                       + <font color="#9933CC">&quot;byte = &quot;</font> + b + <font color="#9933CC">&quot;, &quot;</font>
                       + <font color="#9933CC">&quot;char = &quot;</font> + c + <font color="#9933CC">&quot;, &quot;</font>
                       + <font color="#9933CC">&quot;int = &quot;</font> + i + <font color="#9933CC">&quot;, &quot;</font>
                       + <font color="#9933CC">&quot;long = &quot;</font> + l + <font color="#9933CC">&quot;, &quot;</font>
                       + <font color="#9933CC">&quot;float = &quot;</font> + f + <font color="#9933CC">&quot;, &quot;</font>
                       + <font color="#9933CC">&quot;double = &quot;</font> + d);
  }
}
</code></pre>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -