简体   繁体   中英

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?

Just to elaborate on what duffymo said:

Java is designed to be backward compatible. Ie if you write something in 1.5 you can run it in 1.6. Of course there are limits to that (eg new reserved words like assert break it) but in general it works fine.

If you go the other way, it's a bit more dangerous. You certainly won't need to rewrite all your code, but you might have used features only available since 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.

But beware, that your 1.6 compiler most certainly compiles against a 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.

Setting the compliance level only means that the 1.5 JRE will understand the code, not that all "default" classes are available.

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.

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.

Since Swing didn't change much in the last ten years, you should not run into many problems. Java 6 also hasn't many new features over Java 5 (mostly internal cleanup).

I suggest to just try to compile your app with Java 5 and run it. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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