简体   繁体   English

Java Swing 1.6 至 1.5

[英]Java Swing 1.6 to 1.5

Is it possible to port a UI developed using Swing in Java 1.6 to Java 1.5 without rewriting all again?是否可以将使用 Java 1.6 中的 Swing 开发的 UI 移植到 Java 1.5 而无需重新全部重写?

Just to elaborate on what duffymo said:只是为了详细说明duffymo所说的:

Java is designed to be backward compatible. Java 旨在向后兼容。 Ie if you write something in 1.5 you can run it in 1.6.即,如果您在 1.5 中编写某些内容,您可以在 1.6 中运行它。 Of course there are limits to that (eg new reserved words like assert break it) but in general it works fine.当然,这是有限制的(例如,新的保留字如assert break it)但总的来说它工作正常。

If you go the other way, it's a bit more dangerous.如果你 go 反过来,那就更危险了。 You certainly won't need to rewrite all your code, but you might have used features only available since 1.6.您当然不需要重写所有代码,但您可能使用了自 1.6 起才提供的功能。 Such features can be new classes or new methods of existing classes.这些特征可以是新类或现有类的新方法。

Another thing is the binary code level.另一件事是二进制代码级别。 You can set your compiler running 1.6 to create code for 1.5 or even 1.4.你可以设置你的编译器运行 1.6 来创建 1.5 甚至 1.4 的代码。

But beware, that your 1.6 compiler most certainly compiles against a 1.6 rt.jar.请注意,您的 1.6 编译器肯定会针对 1.6 rt.jar 进行编译。 That means you won't notice missing classes or methods until you actually run or compile your code with 1.5.这意味着在您使用 1.5 实际运行或编译代码之前,您不会注意到缺少的类或方法。

Setting the compliance level only means that the 1.5 JRE will understand the code, not that all "default" classes are available.设置合规级别仅意味着 1.5 JRE 将理解代码,而不是所有“默认”类都可用。

I don't have any experience with 1.6 specifics, but i think while 1.5 added a lot of new language features (that are not all compatible with 1.4), 1.6 was more of a maintenance release.我对 1.6 的细节没有任何经验,但我认为虽然 1.5 添加了许多新的语言功能(并非全部与 1.4 兼容),但 1.6 更像是一个维护版本。

If you've only used features that are common between the two, I'd say yes.如果您只使用了两者之间共有的功能,我会说是的。 It should be backwards compatible.它应该是向后兼容的。 The moment you add JDK 6 specific features you have to take those out.添加 JDK 6 特定功能的那一刻,您必须将其删除。

Since Swing didn't change much in the last ten years, you should not run into many problems.由于 Swing 在过去十年中没有太大变化,因此您应该不会遇到很多问题。 Java 6 also hasn't many new features over Java 5 (mostly internal cleanup). Java 6 也没有比 Java 5 更多的新功能(主要是内部清理)。

I suggest to just try to compile your app with Java 5 and run it.我建议尝试使用 Java 5 编译您的应用程序并运行它。 It might work out of the box.它可能开箱即用。

If you want to assure your code runs in a 1.5 environment, set your IDE to to build against the 1.5 JDK, that way you won't inadvertently use any of the new API.如果您想确保您的代码在 1.5 环境中运行,请将您的 IDE 设置为针对 1.5 JDK 构建,这样您就不会无意中使用任何新的 API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM