New features for Java applets

Java 6 Update 10, released in October 2008, contains significant changes for running Java applets. Many of these new features can be utilized without any changes to an applet's code, they just require changes to the deployment of the applet, but some do require code changes.

These new features are currently available in Firefox 3, Chrome and Internet Explorer 6 & 7, on Windows or Linux - there is no OS X support yet.

New features in Java 6 Update 10:

  • Speed: Smaller, incremental JRE download and faster applet startup.
  • Stability: Applets run in a separate process to the browser, and each applet can optionally run in a separate JVM instance, so one misbehaving applet cannot affect other applets or the browser.
  • Configuration: Applets can have parameters passed to them to control behaviour, such as setting a large initial heap size to avoid out of memory exceptions.
  • Draggable applets: Applets can now be dragged out of the web browser and run as separate applications.

BFO changed its PDF Viewer Applet to take advantage of these new features, and you can see a video of these new features in action at http://www.screencast-o-matic.com/watch/cQVQeynE5.

In this blog entry we'll discuss the changes made to the applet and its deployment for Java 6 Update 10, and from that you can see how to deploy the PDF applet in your own organisation to take advantage of these features.

New features:

1 - Draggable applets.

If you activate this feature then users can use ALT-Click to drag the applet out of the browser. (Note: On Ubuntu ALT-Click is used to move windows by default, so you need to change this by opening System-Preferences-Windows and selecting an alternative movement key mapping).

To activate this functionality you just need to add the following parameter to your APPLET tag:

<param name="draggable" value="true"/>
   

Users can then drag the PDF Viewer applet out of the browser, as shown below.

This will enable the dragging functionality, but by default the applet will not look like a standard application when it is dragged, to do that you need to implement the following methods in your applet class:

public void appletDragStarted();
public void appletDragFinished();
public void setAppletCloseListener(ActionListener l) ;
public void appletRestored();
    

These methods allow you to put the applet in a standard window frame and do any other necessary changes when the applet is dragged from the browser. See http://www.oracle.com/technetwork/articles/javase/index-137083.html for more details on these methods.

You should also provide a JNLP file in order for this to work, as once the applet is dragged out of the browser it uses the Java WebStart functionality, which relies on the JNLP file.

2 - Separate JVM

To specify that your applet should run in its own JVM instance then you can use the 'separate_jvm' APPLET parameter:

<param name="separate_jvm" value="true"/>
  

Once you have added these features to your APPLET tag it should look something like this:

<applet code="org.faceless.pdf2.viewer2.PDFViewerApplet" 
  name="pdfapplet" codebase="applet" archive="bfopdf.jar" 
  style="width:100%; height:500px; display:block"/>
 <param name="feature.MultiWindow" value="false" />
 <param name="feature.Toolbars" value="false" />
 <param name="feature.Menus" value="false" />
 <param name="liveconnect.DocumentPanelListener" 
     value="documentUpdated" />
 <!-- Identify a JNLP file to be used by--> 
 <!-- Java 6 Update 10 and above -->
 <param name="jnlp_href" value="bfopdf-applet.jnlp"/>
 <!-- Request a draggable applet -->
 <param name="draggable" value="true"/>
 <!-- Request a separate JVM instance -->
 <param name="separate_jvm" value="true"/>
 <!-- The next three parameters control the -->
 <!-- logo displayed when the applet is loading -->
 <param name="image" value="http://bfo.com/external/loading.gif"/>
 <param name="boxborder" value="false">
 <param name="centerimage" value="true">
</applet>

You can easily remove any of the features that you do not wish to be available (e.g. draggable applets).

To complete the deployment we need to supply a JNLP file for the applet, which we reference as a parameter from the APPLET tag, such as:

<param name="jnlp_href" value="bfopdf-applet.jnlp"/>

The use of JNLP files for applet deployment is one of the main changes in Update 10. Once the JVM sees the 'jnlp_href' parameter then it will pick up details about the Applet JAR file, main class, widht and height from the JNLP file, ignoring anything set in the APPLET tag.

This means that you can use the APPLET details to deploy the applet to clients running older JRE versions, and the JNLP file to deploy the applet to customers on newer JREs. This enables you to run different code, by deploying different JARs, for pre or post Update 10 JREs.

Full details of the JNLP specification for applets can be found here: http://www.oracle.com/technetwork/java/javase/jnlp-136707.html, but we will discuss the features enabled in the PDF Viewer Applet.

3 - Desktop shortcut:

When an applet is dragged outside a browser and the user closes the browser window, the applet is then running as a Java WebStart application from the JNLP file, and it can optionally place a WebStart link on the user's desktop so that they can easily launch the WebStart applet again. The entries in the JNLP 'information' section below enable this, and also specify a title and custom icon to use for the shortcut:

 <information>
   <title>BFO PDF Viewer</title>
   .....
   <shortcut online="false">
       <desktop />
   </shortcut>
   <icon href="http://bfo.com/external/pdfviewerdesktopicon.gif"/>         

Due to a bug in Java the desktop icon used for a dragged applet in Vista and Ubuntu is only 32 x 32, scaled up to 48 x 48, so the desktop icon doesn't look quite as smooth as it could, but it is adequate, as shown below.

4 - Increased heap size:

JNLP files allow you to specify particular JRE versions that your applet is compatible with. Along with a version you can also set the initial and maximum heap sizes to use for that JRE version. In the example below we state that we are compatible with any JRE 1.4 or later, and require a 256MB heap size.

<resources>
  .....
  <!-- Specify that we need Java 1.4 or above, -->
  <!-- and want 256MB heap size -->
  <j2se version="1.4+" maximum-heap-size="256M"/>
  

You can also specify an initial heap size, but we have not found a way of using this and the maximum heap size without an error occurring, so we just use the maximum heap size.

If you put those new features together with the standard JNLP file contents and use an <applet-desc> element, instead of the usual <application-desc>, to provide the applet's size and main class then you should have a JNLP file that looks something like this:

<jnlp spec="1.0+" 
  codebase="http://bfo.com/products/pdf/applet" 
  href="pdfapplet.jnlp">
  <information>
    <title>BFO PDF Viewer</title>
    <vendor>Big Faceless Organization</vendor>
    <homepage>http://bfo.com/products/pdf</homepage>
    <offline-allowed/>
    <description kind="short">
      The BFO PDF Viewer provides a cross-platform 
      applet and application to allow viewing and 
      printing of PDF documents.
    </description>        
    <!--Create a shortcut on the desktop if--> 
    <!--the user drags the applet out of the browser-->
    <shortcut online="false">
        <desktop />
    </shortcut>
    <icon href="http://bfo.com/external/pdfviewerdesktopicon.gif"/>
  </information>
  <security>
    <all-permissions/>
  </security>
  <resources>
    <!-- Get Pack200 version if available -->
    <property name="jnlp.packEnabled" value="true"/>
    <!-- Specify that we need Java 1.4 or above, -->
    <!-- and want 256MB heap size -->
    <j2se version="1.4+" maximum-heap-size="256M"/>
    <!-- The jar our applet is contained in -->
    <jar href="bfopdf.jar" main="true"/>
    <!-- Other required JARs, loaded on demand -->
    <jar href="bfopdf-cmap.jar" part="cmap" download="lazy"/>
    <jar href="bfopdf-qrcode.jar" part="qrcode" download="lazy"/>
    <jar href="bfopdf-stamp.jar" part="stamp" download="lazy"/>
    <package name="org.faceless.pdf2.resources.encodings.*" 
      part="cmap" recursive="true"/>
    <package name="org.faceless.pdf2.resources.qrcode.*" 
      part="qrcode" recursive="true"/>
    <package name="org.faceless.pdf2.resources.canvases.stamp" 
      part="stamp" recursive="true"/>        
  </resources>
  <applet-desc name="PDF Viewer" 
    main-class="org.faceless.pdf2.viewer2.PDFViewerApplet" 
    width="600" height="500">
  </applet-desc>
</jnlp>
  

The new features and improvements in Java 6 Update 10 make applets better for end-users to use and easier for developers to deploy. If you haven't already done so then it really is worth upgrading to the latest version, which you can download from www.java.com.

代做工资流水公司赣州自存流水报价莆田转账银行流水模板南京代办公司银行流水常州工资代付流水代开宁波代做车贷银行流水福州制作工资流水账单德阳代办购房银行流水宿迁企业对公流水开具黄冈银行流水账单制作许昌查签证流水福州购房银行流水制作中山代办离职证明包头公司流水代做衡阳工资银行流水办理阜阳入职工资流水打印南宁入职工资流水模板长沙办理流水单金华流水多少钱德阳代办企业流水打印重庆个人银行流水多少钱南京贷款工资流水 开具孝感流水单模板珠海贷款工资流水 查询孝感做企业贷流水菏泽工作收入证明图片泰安贷款银行流水办理荆州流水账单代开莆田办理收入证明洛阳办购房银行流水徐州转账流水查询香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声卫健委通报少年有偿捐血浆16次猝死汪小菲曝离婚始末何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言男子被猫抓伤后确诊“猫抓病”周杰伦一审败诉网易中国拥有亿元资产的家庭达13.3万户315晚会后胖东来又人满为患了高校汽车撞人致3死16伤 司机系学生张家界的山上“长”满了韩国人?张立群任西安交通大学校长手机成瘾是影响睡眠质量重要因素网友洛杉矶偶遇贾玲“重生之我在北大当嫡校长”单亲妈妈陷入热恋 14岁儿子报警倪萍分享减重40斤方法杨倩无缘巴黎奥运考生莫言也上北大硕士复试名单了许家印被限制高消费奥巴马现身唐宁街 黑色着装引猜测专访95后高颜值猪保姆男孩8年未见母亲被告知被遗忘七年后宇文玥被薅头发捞上岸郑州一火锅店爆改成麻辣烫店西双版纳热带植物园回应蜉蝣大爆发沉迷短剧的人就像掉进了杀猪盘当地回应沈阳致3死车祸车主疑毒驾开除党籍5年后 原水城县长再被查凯特王妃现身!外出购物视频曝光初中生遭15人围殴自卫刺伤3人判无罪事业单位女子向同事水杯投不明物质男子被流浪猫绊倒 投喂者赔24万外国人感慨凌晨的中国很安全路边卖淀粉肠阿姨主动出示声明书胖东来员工每周单休无小长假王树国卸任西安交大校长 师生送别小米汽车超级工厂正式揭幕黑马情侣提车了妈妈回应孩子在校撞护栏坠楼校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变老人退休金被冒领16年 金额超20万西藏招商引资投资者子女可当地高考特朗普无法缴纳4.54亿美元罚金浙江一高校内汽车冲撞行人 多人受伤

代做工资流水公司 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化

代做工资流水公司赣州自存流水报价莆田转账银行流水模板南京代办公司银行流水常州工资代付流水代开宁波代做车贷银行流水福州制作工资流水账单德阳代办购房银行流水宿迁企业对公流水开具黄冈银行流水账单制作许昌查签证流水福州购房银行流水制作中山代办离职证明包头公司流水代做衡阳工资银行流水办理阜阳入职工资流水打印南宁入职工资流水模板长沙办理流水单金华流水多少钱德阳代办企业流水打印重庆个人银行流水多少钱南京贷款工资流水 开具孝感流水单模板珠海贷款工资流水 查询孝感做企业贷流水菏泽工作收入证明图片泰安贷款银行流水办理荆州流水账单代开莆田办理收入证明洛阳办购房银行流水徐州转账流水查询香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声卫健委通报少年有偿捐血浆16次猝死汪小菲曝离婚始末何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言男子被猫抓伤后确诊“猫抓病”周杰伦一审败诉网易中国拥有亿元资产的家庭达13.3万户315晚会后胖东来又人满为患了高校汽车撞人致3死16伤 司机系学生张家界的山上“长”满了韩国人?张立群任西安交通大学校长手机成瘾是影响睡眠质量重要因素网友洛杉矶偶遇贾玲“重生之我在北大当嫡校长”单亲妈妈陷入热恋 14岁儿子报警倪萍分享减重40斤方法杨倩无缘巴黎奥运考生莫言也上北大硕士复试名单了许家印被限制高消费奥巴马现身唐宁街 黑色着装引猜测专访95后高颜值猪保姆男孩8年未见母亲被告知被遗忘七年后宇文玥被薅头发捞上岸郑州一火锅店爆改成麻辣烫店西双版纳热带植物园回应蜉蝣大爆发沉迷短剧的人就像掉进了杀猪盘当地回应沈阳致3死车祸车主疑毒驾开除党籍5年后 原水城县长再被查凯特王妃现身!外出购物视频曝光初中生遭15人围殴自卫刺伤3人判无罪事业单位女子向同事水杯投不明物质男子被流浪猫绊倒 投喂者赔24万外国人感慨凌晨的中国很安全路边卖淀粉肠阿姨主动出示声明书胖东来员工每周单休无小长假王树国卸任西安交大校长 师生送别小米汽车超级工厂正式揭幕黑马情侣提车了妈妈回应孩子在校撞护栏坠楼校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变老人退休金被冒领16年 金额超20万西藏招商引资投资者子女可当地高考特朗普无法缴纳4.54亿美元罚金浙江一高校内汽车冲撞行人 多人受伤

代做工资流水公司 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化