-
运用Java的JNI技术来实现清屏功能
资源介绍
用java实现在命令方式清屏
java实现清屏功能
1. 编写一个类ClearScreen.java
public class ClearScreen{
Static
{
loadLibrary("Clear");
}
public native static void clearScreen();
public static void main(String[] args){
clearScreen();
}
}
2. javac ClearScreen.java -> ClearScreen.class
3. javah ClearScreen -> ClearScreen.h
4. 编写ClearScreen.cpp实现native方法clearScreen();
#include
#include "ClearScreen.h"
#include
JNIEXPORT VOID JNICALL Java_ClearScreen_clearScreen(JNIEnv *, jclass)
{
system("cls");
}
5.安装一个microsoft compiler 编译ClearScreen.cpp,得到Clear.dll
注意:将Jdk安装环境include目录下的jawt_md.h jni_md.h jni.h三个头文件copy到 Microsoft Visual Studio的include目录下
cl -LD ClearScreen.cpp -FeClear.dll
其中 -LD create .dll -Fe name executable file