java com.sun.awt 包使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4941337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:42:32  来源:igfitidea点击:

com.sun.awt package usage

javasun

提问by sajad

I found a java codeand want to use it in my project. It contains these imports that my JDKdoes not have :

我找到了一个 javacode并想在我的项目中使用它。它包含我JDK没有的这些导入:

import com.sun.awt.AWTUtilities;
import com.sun.jna.Native;
import com.sun.jna.platform.WindowUtils;

I referred to sun site and found this download page :

我参考了 sun 网站,找到了这个下载页面:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Is it necessary to download all JDKand JREand replace it from SUN website? My JDKis version 6 and is up to date.

是否有必要下载所有JDK,并JRE从SUN网站更换呢?我的JDK是第 6 版并且是最新的。

Thank you all

谢谢你们

回答by josefx

JNAis an additional library and not part of the standard api, you have to download it (here) and include it in your classpath.

JNA是一个额外的库,而不是标准 api 的一部分,您必须下载它(这里)并将其包含在您的类路径中。

The AWTUtilitiesclass is only distributed with the sun jvm as an implementation detail of the api and as such subject to change, this can break any program depending on it (if possible don't use it).

AWTUtilities班仅与太阳的JVM的API的实现细节分布,因此可能发生变化,这可以打破依赖于它的任何程序(如果可能不使用它)。

WindowUtilscan be found in the platform.jar, you it can find it on the same page as jna.

WindowUtils可以在platform.jar中找到,你可以在与jna相同的页面上找到它。

回答by Stephen C

Your JDK should have com.sun.awt.AWTUtilities. It is in rt.jar.

你的 JDK 应该有com.sun.awt.AWTUtilities. 它在rt.jar.

Maybe the problem (for that file) is that your IDE excludes the parent the build path ... on the grounds that it is a bad idea to use those classes directly.

也许问题(对于那个文件)是你的 IDE 排除了父级的构建路径......因为直接使用这些类是个坏主意。

The com.sun.jnaclasses are not in rt.jar. They apparently may be found in a jna.jar, though I haven't yet found a good place to download it from. (If you use Maven, try this.)

com.sun.jna班是不是rt.jarjna.jar虽然我还没有找到下载它的好地方,但它们显然可以在. (如果你使用 Maven,试试这个。)

回答by James Kingsbery

You should not use any com.sun packages except as a last resort. These are considered to be implementation details, and they are not part of the JDK API. They can change arbitrarily between versions, so they can cause problems when you try to upgrade JDK versions.

除非万不得已,否则不应使用任何 com.sun 软件包。这些被认为是实现细节,它们不是 JDK API 的一部分。它们可以在版本之间任意更改,因此当您尝试升级 JDK 版本时,它们可能会导致问题。

The com.sun classes are almost always wrapped by "official" classes - you should use those instead. You can use these in a last resort situation, but they are already part of the JDK download, so there should be no extra downloading necessary.

com.sun 类几乎总是由“官方”类包装 - 您应该改用它们。您可以在万不得已的情况下使用这些,但它们已经包含在 JDK 下载中,因此不需要额外下载。

EDIT: Looks like you're right, you do need to download some extra jars. The JNA jar is available on maven central (http://mvnrepository.com/artifact/com.sun.jna/jna/3.0.9). Especially if this is a code snippet you found, I would highly advise against using com.sun packages directly.

编辑:看起来你是对的,你确实需要下载一些额外的罐子。JNA jar 在 maven central (http://mvnrepository.com/artifact/com.sun.jna/jna/3.0.9) 上可用。特别是如果这是您找到的代码片段,我强烈建议不要直接使用 com.sun 包。