com.sun.awt package usage

眉间皱痕 提交于 2019-11-30 20:24:19
josefx

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

The AWTUtilities class 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).

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

Your JDK should have com.sun.awt.AWTUtilities. It is in 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.

The com.sun.jna classes 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.)

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.

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!