JavaÖÐÈçºÎµ÷ÓÃVCµÄ¶¯Ì¬¿â
ÒÔǰһƪµÄDLLΪÀý²ûÊöJavaÈçºÎµ÷Óö¯Ì¬¿â
Ŀǰ´æÔÚÒ»¸öVC±àÒëµÄ·ÇMFC¶¯Ì¬¿âDLL£¨¾ßÌåÈçºÎÉú³É·ÇMFC¶¯Ì¬¿âDLL¼ûǰһƪÎÄÕ£©£¬Ãû³ÆÎªmydll.dll£¬ÆäÖÐÓе¼³öº¯Êýmyadd£ºÐÎÈ磺int myadd(int,int)£¬ÏÖjavaÓ¦ÓóÌÐòÐèÒªµ÷Óøö¯Ì¬¿âµÄmyaddº¯Êý¡£¾ßÌåʵÏÖ²½ÖèÈçÏ£º
1¡¢±àдµ÷ÓÃmydll.dllµÄjava³ÌÐò
£¨1£©³ÌÐòtestMyDll .javaÈçÏ£º
public class testMyDll {
private native static int myadd(int a,int b);
static {
System.loadLibrary("javamydll"); //¸Ã¶¯Ì¬¿âÃû³ÆÎªÖм䶯̬¿â£¬ÓÉjava³ÌÐòʹÓ㬸ºÔðµ÷ÓÃÐèҪʹÓõĶ¯Ì¬¿â¡£
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(myadd(4,5));
}
}
£¨2£©±àÒëtestMyDll .java³ÌÐò£¬¼ì²éÊÇ·ñ´æÔÚ´íÎó¡£
javac testMyDll .java
2¡¢Éú³ÉÍ·ÎļþtestMyDll.h£¬¹©Éú³ÉÖм䶯̬¿âʹÓá£
javah testMyDll
3¡¢Éú³ÉÖм䶯̬¿âjavamydll.dll
£¨1£©Ê¹ÓÃvc¹¤¾ßÏÈÉú³Éwin32 Dynamic-Link Library¿Õ¹¤³Ì
£¨2£©½«ÉÏÃæÉú³ÉµÄÍ·ÎļþtestMyDll.hÌí¼Ó½øÈ¥£¬Í¬Ê±»¹ÐèÒªÌí¼ÓjdkÏÂincludeĿ¼ÖÐ µÄjni.h¡¢jni_md.hÕâÁ½¸öÍ·Îļþ£¬×îºÃ½«jni.hÎļþ·ÅÈ밲װĿ¼ÏÂincludeµÄĿ¼ÏÂ
£¨3£©Ìí¼Óµ÷ÓÃÐèҪʹÓõĶ¯Ì¬¿âµÄʵÏÖÎļþtestMyDll.cpp
³ÌÐòÈçÏ£º
//testMyDll.cpp
#include <windows.h>
#include "testMyDll.h"
typedef int (*padd)(int,int);
JNIEXPORT jint JNICALL Java_testMyDll_myadd
(JNIEnv * a, jclass b, jint x, jint y)
{
HINSTANCE hins = ::LoadLibrary("mydll.dll");
if(hins == NULL)
{
return 0;
}
int res;
padd pa = (padd)GetProcAddress(hins,"myadd");
if(pa != NULL)
{
res = x+y;
}
::FreeLibrary(hins);
return res;
}
£¨4£©±àÒëÉú³ÉÖм䶯̬¿âjavamydll.dll
4¡¢½«Öм䶯̬¿âjavamydll.dllºÍÐèʹÓõĶ¯Ì¬¿âmydll.dll·ÅÔÚtestMyDll.classĿ¼Ï£¬ÔËÐиÃÀà: java testMyDll
³ÌÐòÊä³ö½á¹û£º9
´ÓÉÏÊöʵÏÖ·½·¨ÖпÉÒÔ¿´µ½£¬javaÐèÒªµ÷ÓÃÒÑÓеĶ¯Ì¬¿â£¬»¹ÐèÒª×Ô¼ºÉú³ÉÒ»¸öÖм䶯̬¿â£¬¸ºÔðµ÷ÓÃת»»¡£ËùÒÔЧÂʾͻáÓеãµÍ¡£
Ïà¹ØÎĵµ£º
ÏÈÀ´Á˽âÒ»ÏÂÁ´±íģʽµÄÔÀí£º
Ê×ÏÈдһ¸öJavaBean£¬ÄÚÈÝÊÇÒªÌí¼ÓµÄÔªËØºÍ¸ÃÔªËØµÄ½Úµã¡£
public class NodeBean implements Serializable
{
private Object data; //ÔªËØ±¾Éí
private NodeBean next; //ÏÂÒ»¸ö½Úµã
&n ......
1¡¢ ÀàÐÍ×°ÔØ¡¢Á´½ÓÓë³õʼ»¯
JavaÐéÄâ»úͨ¹ý×°ÔØ¡¢Á´½ÓºÍ³õʼ»¯Ò»¸öJavaÀàÐÍ£¬Ê¹¸ÃÀàÐÍ¿ÉÒÔ±»ÕýÔÚÔËÐеÄJava³ÌÐòËùʹÓá£ÆäÖУ¬×°ÔؾÍÊǰѶþ½øÖƵÄJavaÀàÐͶÁÈëJavaÐéÄâ»úÖУ¬¶øÁ¬½Ó¾ÍÊǰÑÕâÖÖÒѾ¶ÁÈëÐéÄâ»úµÄ¶þ½øÖÆÐÎʽµÄÀàÐÍÊý¾ÝºÏ²¢µ½ÐéÄâ»úµÄÔËÐÐ״̬ÖÐÈ¥¡£Á¬½Ó½×¶Î·ÖÁËÈý¸ö²½Ö裺Ñé ......
½ñÌìѧϰÁËapplet²¼¾ÖÎÊÌ⣺
°´Å¥¡¢±êÇ©ÊÇÔõÑù¼ÓÈëµ½applet³ÌÐò(ÈÝÆ÷)µ±ÖÐÈ¥µÄÄØ£¿
ÐèÒªÓõ½²¼¾ÖÈÝÆ÷¹ÜÀíÆ÷(LayoutManager)£ºËüÓÃÓÚÐÖúÈÝÆ÷È·¶¨¼ÓÈëµÄ×é¼þ(°´Å¥µÈ)Ó¦¸Ã·ÅÖõÄλÖÃ
awtÌṩÁË4Öг£ÓõIJ¼¾ÖÈÝÆ÷¹ÜÀíÆ÷
>>FlowLayout
>>BorderLayout
>>GridLayout
>>CardLayout
appletĬÈÏÊ ......
¹Ø¼ü×Ö: java·ÖÒ³´úÂëʵÀý
package com.hjf.web.view;
public class PageUtil ...{
private int pageSize;//ÿҳÏÔʾµÄÌõÊý
private int recordCount;//×ܹ²µÄÌõÊý
private int currentPage;//µ±Ç°Ò³Ãæ
publi ......