JOptionPane.showMessageDialog(null, "对话框文字");
JEditorPane:
// 清空内容:
jEditorPane.setText(""); // 会残留一些样式,想彻底清空可用下行:
jEditorPane.setDocument(jEditorPane.getEditorKit().createDefaultDocument());
// 滚动至底部:
jEditorPane.setCaretPosition(jEditorPane.getDocument().getLength());
关闭所有extends WindowAdapter覆写了windowClosing方法的窗口:
var we = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(we);
JDK FFM(Foreign Function & Memory API)取代JNA和JNI之系统调用C库实例(JDK22正式支持):
var nl = Linker.nativeLinker();
var mh = nl.downcallHandle(nl.defaultLookup().find("_getpid").get(),
FunctionDescriptor.of(JAVA_INT)); //or FunctionDescriptor.ofVoid(...)
// mh.invokeExact(Arena.openConfined().allocateUtf8String("x"));
var r = (int) mh.invokeExact(); System.out.println(r);
纯Java获取Process ID (PID):ProcessHandle.current().pid();
如果库文件规模过大,可采用jextract方式生成Java待调用的胶水代码:
jextract 抽取C库头文件生成 Foreign Function & Memory API 绑定类
库主要分为两类:静态库和动态库(共享库)。
1. windows中静态库是以 .lib 为后缀的文件,动态库是以 .dll 为后缀的文件。
2. linux中静态库是以 .a 为后缀的文件,动态库是以 .so为后缀的文件。
3. mac中静态库是以.a为后缀的文件,动态库是以.dylib为后缀的文件。