论坛首页 Java企业应用论坛

Applets重装上阵: 新标签和示例总览(翻译)(上半部分)

浏览 7373 次
该帖已经被评为精华帖
作者 正文
   发表时间:2008-04-11  

原文地址http://java.dzone.com/news/applets-reloaded-overview-new-

Applets Reloaded: An Overview of New Tags and Demos

Applets重装上阵: 新标签和示例总览

What's the deal with applets in JDK 6 Update 10? In this article, we walk through the new applet tags and see some JNLP-powered applets in the wild.

Applet在新的JDK 6 Update 10中到底是个什么样子?在这篇文章里,我们将会遍历一下新的applet 标签并且看看新的基于JNLPapplet真正是如何运作的!

If you're used to creating applet tags that look like this:

如果你以前创建的applet标签是像这样的:

<applet code="org.me.hello.MyApplet" archive="HelloApplet.jar"></applet>

...then you're in for a surprise. Here are the new parameters that you should be aware of:

……那么,你肯定会很吃惊。以下是你需要知道的新参数:

·                     "jnlp_href". Probably the most important new parameter, it lets you launch an applet from a JNLP (web start) file.

·                     "jnlp_href". 也许是最重要的新参数, 它允许你从一个JNLPweb start)文件中启动applet.

·                     "boxborder". Offers support for the "image" attribute, specifying whether a one-pixel border should be drawn around the edge of the applet's area while displaying the image shown before the applet is loaded.

·                     "boxborder".为“image”属性提供支持。当applet还没有被载入的时候,浏览器会在applet所在的位置显示载入画面,这个参数用来指定是否要在此时给浏览器中applet的范围画上一个一像素宽的边界。

·                     "centerimage". Offers support for the "image" attribute, specifying whether the loading image should be centered within the area of the applet instead of originating at the upper left corner.

·                     "centerimage".为“image”属性提供支持。用来指定载入画面是否要被放置在applet区域的中间而不是默认的显示在左上角。

·                     "java_arguments." Specifies JVM command-line arguments to be used when executing this applet instance. Nearly all JVM command-line arguments are supported, though there are certain rules and restrictions.

·                     "java_arguments." 指定在执行applet实例时的JVM命令行参数。几乎所有的JVM命令行参数都可以使用,虽然有一些特别的规定和限制。

·                     "java_version." Specifies a JRE version upon which to launch a particular applet.

·                     "java_version." 指定特定applet运行的JRE版本。

·                     "separate_jvm." Specifies a separate JVM for an applet, specifically for powerful applets that cannot tolerate interference during deployment.

·                     "separate_jvm." 为这个applet指定一个单独的虚拟机,主要是为了那些在部署时不能容忍干扰的强大的applet而用。

·                     "classloader_cache." Lets an applet opt out of the use of the class loader cache on an applet by applet basis.

·                     "classloader_cache." applet避免使用class loader cache

For a full description of the above new parameters,see Release Notes for the Next-Generation Java™ Plug-In Technology. You will find that the improvements for applets in JDK 6 Update 10 are as follows:

对于上面这些新参数的全面介绍, 请参考 Release Notes for the Next-Generation Java™ Plug-In Technology. 你会发现applet JDK 6 Update 10 有了如下改善:

·                     Improved reliability. The JVM running the applet is isolated from the web browser at the operating system level. If something should go wrong while running the applet, or if an uncooperative applet refuses to shut down, the new Java Plug-In detects and handles the error condition gracefully; the web browser is unaffected.

·                     可靠性增强. 运行applet JVM在操作系统层与网页浏览器分离了开来. 如果在运行applet的时候出现问题,或者一个不合作的applet拒绝关闭,新的Java Plug-in会检测到,并且将出现的错误温柔的处理掉,浏览器不会被影响到。

·                     Built-in JNLP support. The new plug-in offers the capability to launch applets directly from JNLP files, unifying deployment of Java content both in the browser and out of the browser (via Java Web Start). Developers can now reuse JNLP extensions for advanced functionality including the JavaFX run-time libraries, 3D graphics via OpenGL, and planetary-scale terrain visualization within applets. Applets can now access JNLP APIs for persistent data storage, local file system access, and other useful functionality from sandboxed code.

·                     内置的JNLP支持. 新的plug-in提供了直接从JNLP文件启动applet的能力,使得在浏览器内和浏览器外(通过Java Web Start)部署Java程序的方式得到了统一。开发者们现在可以使用JNLP扩展机制来使applet获得高级功能,这包括:JavaFX run-time libraries, 3D graphics via OpenGL, 以及planetary-scale terrain visualization Applet现在可以在sandbox中使用JNLPAPI来进行数据存储,访问本地文件系统,以及其他有用的功能。

·                     Per-applet command-line arguments. JVM command-line arguments may be specified on a per-applet basis, providing fine-grained control over options such as the heap size and Java 2D hardware acceleration features. JNLP-launched applets simply incorporate the command-line arguments and/or system properties into the JNLP file. Old-style applets can embed these arguments in the HTML of the web page.

·                     每个applet特定的命令行参数. JVM命令行参数现在可以对每个applet进行分别定制,可以对JVM选项进行细粒度的控制,例如可使用的内存的大小和Java 2D 硬件加速特性。 基于JNLPapplet可以简单的将命令行参数和系统参数包含进JNLP文件,而旧式的applet可以将这些参数嵌入进HTML页面。

·                     Multiple JRE version support. Each individual applet instance may request a different JRE version on which to run. This feature is designed for enterprise customers which prefer to qualify their applets against either a particular JRE version or a particular JRE family. Both selection of a specific JRE version, or any in a particular family, are supported in the new plug-in.

·                     JRE版本支持.每个单独的applet实例都可以要求在一个不同的JRE版本中运行。部分企业级用户为他们的applet对特定的JRE版本或者特定的JRE系列进行了优化,这项特性是为他们服务的。无论是对JRE版本还是对JRE系列的选择在新的plug-in中都得到了支持.

·                     Improved Java/JavaScript communication. The bridge between the JavaScript engine in the web browser and the Java programming language has been completely reimplemented. The new implementation is backward-compatible and features improved reliability, performance and cross-browser portability, for both Java calling JavaScript as well as JavaScript calling Java. Formerly Mozilla-specific "LiveConnect" functionality, such as the ability to call static Java methods, instantiate new Java objects and reference third-party packages from JavaScript, is now available in all browsers.

·                     增强的Java/JavaScript通信. 浏览器的JavaScript引擎与Java编程之间的通信桥梁被完全重新实现了。新的实现是向后兼容的,并且对于无论是Java调用JavaScript,还是JavaScript调用Java,都进行了可靠性、性能和跨浏览器能力的增强。以前只有Mozilla系列的浏览器拥有的“LiveConnect”功能:如在JavaScript中调用静态Java方法、实例化新的Java 对象以及引用第三方包的能力,现在对于所有的浏览器都是可用的。

·                     Improved user experience. The new Java Plug-In starts applets in the background, so the web browser always remains responsive. Applets appear on the web page as they become ready to run.

·                     改善的用户体验. 新的Java plug-in在后台启动applet,从而使得浏览器可以一直保持响应。Applet只有在已经可以运行时才会出现在网页上.

·                     Improved applet lifecycle management. Calls to the applet lifecycle methods init, start, stop, and destroy are more deterministic and cross-browser behavior has been improved. The applet class loader cache and the legacy applet lifecycle, required for backward compatibility, are fully supported and the behavior of both has been improved.

·                     改善的applet生命周期管理.applet生命周期相关的方法 initstartstop以及destroy更加确定了,并且跨浏览器的行为得到了改善。 Appletclass loader 缓冲和旧applet的生命周期的向后兼容性都得到了支持,并且两者的表现都得到了改善。

·                     Better large heap support. Historically, the maximum heap size that could be specified for applets via the Java Control Panel has been limited. This limitation is fixed in the new Java Plug-In; applets can now utilize as much heap space as command-line applications.

·                     更好的大内存支持. 过去,最大的内存使用量只能由用户在Java Control Panel指定。这样的限制在新的

   发表时间:2008-04-11  

·                     Better large heap support. Historically, the maximum heap size that could be specified for applets via the Java Control Panel has been limited. This limitation is fixed in the new Java Plug-In; applets can now utilize as much heap space as command-line applications.

·                     更好的大内存支持. 过去,最大的内存使用量只能由用户在Java Control Panel指定。这样的限制在新的Java Plug-in中得到了修正;现在applet可以通过命令行参数来制定它们可以使用的内存大小。

·                     Better Windows Vista support. Signed applets running in Protected Mode Internet Explorer on Microsoft's Windows Vista now have the same privileges as normal user applications, eliminating a portability barrier to this platform.

·                     更好的Windows Vista 支持. 对于Windows Vista处于保护模式的IE浏览器,已签名的applet现在享有和其他普通的应用程序相同的特权。这消除了之前对于这个平台的移植障碍。

To get started using the new support for applets, including the above tags, you need JDK 6 Update 10 Beta. If you are using FireFox, you also need some beta version of FireFox 3. The above release notes state, on this point: "Sun Microsystems and the Mozilla Foundation have been working closely in order to support the new Java Plug-In in Firefox 3. Both organizations have mutually decided not to back-port the required changes — which are significant — to Firefox 2, as it is expected that most Firefox users will upgrade to Firefox 3 a short time after its final version has been released."

为了使用这些对于applet新的支持,包括上面的这些标签,你需要安装JDK 6 Update 10 Beta。如果你是FireFox用户,你还需要使用FireFox 3。对于这样的发布状况,解释是:“Sun Microsystems Mozilla Foundation为了能在FireFox 3上支持新的Java Plug-In进行了紧密的合作。两个组织都很成熟的决定不会向后兼容至FireFox 2,而是寄希望于绝大多数的FireFox用户会在FireFox 3最终版发布后的很短时间内,将浏览器升级至FireFox 3

Several examples are already available of the new applet technology in action. I must say that I find them pretty convincing: smooth, no browser freezing, very nice indeed.

目前对于新的applet技术,已经有了一些样例程序。我不得不说,我发现他们非常的有说服力:平滑,无浏览器锁死,真的很不错。

NASA World Wind Applet

Shows how to embed the Earth in full 3D on a web page. Click here for all the deployment info.

展示如何把全3D的地球嵌入到网页当中。点这里来了解部署信息

Jake2 Applet

Game deployment over the web? Check out this one for a great and fun example. Click here for deployment info.

通过网页部署游戏? 这是一有趣例子。点这里来了解部署信息。

Scene Graph Applets

The Scene Graph applets are pretty excellent, showing the power of the new Scene Graph together with the power of the new browser Java plugin. Here's the whole list of them:

Scene Graph applets棒极了 ,同时展示了新的Scene Graph 和新的 Java plugin的强大力量。 这里给出这些样例程序的列表:

Calculator. A simple, functioning, calculator application:

计算器. 一个简单的,功能完全的计算器程序:

SnowMark. Illustrates the use of images, transformations, and effects such as shadows and Gaussian blurs. Click the demo to pause / resume the animation:

雪花. 展示了对图片的使用,变型,以及阴影和高斯模糊。点击样例来暂停和恢复动画。

Egg Timer. A functioning "egg timer" example which can be set for up to 59 minutes:

鸡蛋计时器. 一个可运行的“鸡蛋计时器”,可以定时至59分钟:

Dynamic Demo. Shows several hundred dynamically moving shapes in the scene. Click the demo to pause / resume the animation:

动态示例. 在场景中显示了数百个动态移动的形体. 点击样例来暂停和恢复动画:

JPhone. An example of a modern cell phone UI written using Scene Graph:

JPhone. 一个使用Scene Graph来绘制现代手机用户界面的例子:

NestedText. An example of a JSGPanel nested inside an SGComponent, which is part of the scene of another JSGPanel:

NestedText. 一个使用一个JSGPanel 筑巢(译者:绑定?nested好像是Scene Graph专业术语)于 一个 SGComponent,而后者又是另一个 JSGPanel场景的一部分:

JavaFX Timer Applet

How about JavaFX in an applet? The cool thing is that you also see the source code, when you go to the site.

applet中使用JavaFx?最酷的地方是:你访问这个站点的时候,可以看到源代码。

Finally, I had to try it out myself. I created a small applet, added some Swing components, and deployed it via a JNLP file. First I deployed it to FireFox 2 and got the same old terrible performance. Deployed to FireFox 3, it was a breeze. There's some kind of very gentle introduction of the applet to the browser whereby it seems to unfold before your eyes as it is deployed to the page. A very nice professional effect. And then my applet appeared:

最后, 我自己尝试了一下。 我创建了一个简单的applet,添加了些Swing空间,然后通过JNLP文件部署了它。起初我把它部署到了FireFox 2上,结果得到了和以前一样的糟糕表现。而部署到FireFox 3后,像微风一样流畅!当在applet部署到网页的过程中,载入过程非常流畅,然人感觉applet似乎是在你眼前展开一样。非常漂亮专业的效果。下面是我的applet

Also, because of the JNLP support, applets can access JNLP APIs for persistent data storage, local file system access, and other useful functionality from sandboxed code. All the information you should ever need can be found in Release Notes for the Next-Generation Java™ Plug-In Technology and, especially, in JNLP Support in the New Java Plug-in Technology.

并且, 由于有了JNLP的支持, applet可以从sandbox中通过JNLPAPI进行数据存储,本地文件访问和其它很多有用的功能。所有你要的信息都可以在 Release Notes for the Next-Generation Java™ Plug-In Technology ,尤其是JNLP Support in the New Java Plug-in Technology找到。

 

译者:翻译东西最怕的就是翻不准,虽然是翻这种比较随意的blog,翻错了终究不太好。人都是有惰性的,如果只给出个原帖地址,大多数人即使觉得有问题,也很少跑去原帖核实。所以决定回归以前采用的中英文对照的方法,这样只需要向上看一行就能看到原文,更有助于大家理解和纠错。

最后,对于我的所有文章都一样:水平有限,欢迎大家纠正错别字、语法错误和翻译错误。

0 请登录后投票
   发表时间:2008-04-11  
本来打算发到博客首页,但是在博客新建文章的时候一直无法使用“可视化编辑器”。所以只好发到论坛上来了。论坛发贴长度似乎有限制,我帖子的后半部分老是发不上去,只好在后面跟帖把第二部分发上去,结果造成我博客里的文章只剩前半截~~~

顺便说一下,尽管javaeye的“可视化编辑器”相对比较好,但是基于网页的编辑器实在是非常恶心,尤其是在网速不好的情况下,插入图片的用户体验糟糕透了。强烈建议用flex或者applet写一个好点的。
0 请登录后投票
   发表时间:2008-10-29  
这贴发了6个月了,突然变成精华~~~~
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics