gpt4 book ai didi

java - JNA beep() 找不到符号?

转载 作者:行者123 更新时间:2023-11-30 07:25:54 27 4
gpt4 key购买 nike

在下面的代码中我收到一个错误,但不知何故我找不到信息来修复它。如有任何误解,敬请谅解。

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;
// JNA infrastructure import libs.Kernel32;
// Proxy interface for kernel32.dll

public interface JnaTests extends Library {
public boolean Beep(int FREQUENCY , int DURATION );
static Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
static void toMorseCode(String letter) throws Exception {
for (byte b : letter.getBytes()) {
kernel32.Beep(1200, ((b == '.') ? 50 : 150));
Thread.sleep(50);
}
}
public static void main(String[] args) throws Exception {
String helloWorld[][] = { {"....", ".", ".-..", ".-..", "---"}, {".--", "---", ".-.", ".-..", "-.."}};
for (String word[] : helloWorld) {
for (String letter : word) {
toMorseCode(letter);
Thread.sleep(150);
}
Thread.sleep(350);
}
}
}

最佳答案

感谢您的回答。

最后我发现在一个单独的文件中应该有一个接口(interface)(Kernel32)。

社区文档中提到了这一点,但是某些 .dll 也可以在没有接口(interface)的情况下工作,例如User32.dll 。



<pre><code>package com.sun.jna.platform;

import com.sun.jna.Library;


//@author windows-System

public class win32 {

public interface Kernel32 extends Library {

boolean Beep(int frequency, int duration);
// ... (lines deleted for clarity) ... }
}
</code></pre>

}

主文件



<pre><code>import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.Kernel32;

// JNA infrastructure import libs.Kernel32;
// Proxy interface for kernel32.dll

public class JnaTests {

private static Kernel32 kernel32 = (Kernel32)
Native.loadLibrary ("kernel32", Kernel32.class);

private static void toMorseCode(String letter) throws Exception {
for (byte b : letter.getBytes()) {
kernel32.Beep(1200, ((b == '.') ? 50 : 150));
Thread.sleep(50);
}
}

public static void main(String[] args) throws Exception {
String helloWorld[][] = { {"....", ".", ".-..", ".-..", "---"},
{".--", "---", ".-.", ".-..", "-.."}};

for (String word[] : helloWorld) {
for (String letter : word) {
toMorseCode(letter);
Thread.sleep(150);
}
Thread.sleep(350);
}
</code></pre>

<p>}
}</p>

关于java - JNA beep() 找不到符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36815488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com