<?xml version="1.0"?>
<rss version="2.0">
<channel>
  <title>Weiqi Gao&#039;s Observations - applet tag</title>
  <link>http://www.weiqigao.com/blog/tags/applet/</link>
  <description>Sharing My Experience...</description>
  <language>en</language>
  <copyright>Weiqi Gao</copyright>
  <lastBuildDate>Fri, 11 May 2012 12:48:36 GMT</lastBuildDate>
  <generator>Pebble (http://pebble.sourceforge.net)</generator>
  <docs>http://backend.userland.com/rss</docs>
  
  <image>
    <url>http://pebble.sourceforge.net/common/images/powered-by-pebble.gif</url>
    <title>Weiqi Gao&#039;s Observations</title>
    <link>http://www.weiqigao.com/blog/</link>
  </image>
  
  
  <item>
    <title>This Applet Not Brought To You By...</title>
    <link>http://www.weiqigao.com/blog/2008/10/29/this_applet_not_brought_to_you_by.html</link>
    
      
        <description>
          &lt;p&gt;... a buggy JavaScript file.&lt;/p&gt;

&lt;p&gt;(&lt;em&gt;[&lt;b&gt;Note&lt;/b&gt;] The following would have been a charming little blog entry with a small Java applet that warms people&#039;s hearts, had I not ran into some troubles that made the whole thing, eh, what shall I say, a little annoying.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Along with &lt;a href= &#034;http://java.sun.com/developer/technicalArticles/javase/java6u10/&#034; &gt;Java 6 Update 10&lt;/a&gt;, released &lt;a href= &#034;http://www.weiqigao.com/blog/2008/10/15/java_6_update_10_released.html&#034; &gt;14 days ago&lt;/a&gt;, comes a JavaScript file &lt;a href= &#034;http://java.com/js/deployJava.js&#034; &gt;deployJava.js&lt;/a&gt; hosted at http://java.sun.com, that, among other things, helps in deploying Java applets.&lt;/p&gt;

&lt;p&gt;Here&#039;s a little applet, deployed according to &lt;a href= &#034;http://java.sun.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#appletTagAttributes&#034; &gt;this advice&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Source of a would-be applet follows)&lt;/em&gt;&lt;/p&gt;
&lt;pre style=&#034;margin-left:3em&#034;&gt;&amp;lt;div style=&#034;margin-left:3em&#034;&gt;
&amp;lt;script src=&#034;http://java.com/js/deployJava.js&#034;&gt;&amp;lt;/script&gt;
&amp;lt;script&gt;
    var attributes =
        {id:&#039;squareApplet&#039;,
        codebase:&#039;http://www.weiqigao.com/blog/files&#039;,
        code:&#039;com.weiqigao.square.SquareApplet.class&#039;,
        archive:&#039;square.jar&#039;,
        width: 100, height:100};
    var parameters = {color: &#039;red&#039;};
    var version = &#039;1.6&#039; ;
    deployJava.&lt;span style=&#034;color:red&#034;&gt;runApplet&lt;/span&gt;(attributes, parameters, version);
&amp;lt;/script&gt;&lt;span style=&#034;color:red&#034;&gt;&amp;lt;/applet&gt;&lt;/span&gt;
&amp;lt;/div&gt;

&amp;lt;script&gt;
  function toBlue() {
    document.squareApplet.toBlue();
  }

  function toRed() {
    document.squareApplet.toRed();
  }
&amp;lt;/script&gt;

&amp;lt;p&gt;And you can change its color to &amp;lt;a href=  &#034;javascript:toBlue()&#034;
&gt;blue&amp;lt;/a&gt; and &amp;lt;a href= &#034;javascript:toRed()&#034; &gt;back&amp;lt;/a&gt;.&amp;lt;/p&gt;&lt;/pre&gt;

&lt;p&gt;Here&#039;s the issues I had with this setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I don&#039;t have Java plug-in on my 64-bit Debian GNU/Linux machine.  This causes the above script to auto-redirect to &lt;a href= &#034;http://java.com/en/download/linux_manual.jsp?host=java.com&amp;returnPage=http://www.weiqigao.com/blog/&amp;locale=en-US&#034; &gt;Java Downloads for Linux&lt;/a&gt;.  But it forgot one thing: there isn&#039;t a Java plug-in for 64-bit Linux to download.  In the mean time, I can&#039;t even go back to the blog entry to edit it.&lt;/li&gt;

&lt;li&gt;So I switched to the Windows machine to finish the editing.  For some reason, the tags output by the JavaScript is missing the closing applet tag, which, in Firefox or IE7 causes the Save button to not show up.&lt;/li&gt;

&lt;li&gt;Luckily, Google Chrome was more tolerant, and I was able to resume my editing.  I added the closing &amp;lt;/applet&gt; tag after the JavaScript code to make it work in Firefox 3 and IE7.&lt;/li&gt;

&lt;li&gt;One thing I want to experiment with is the revived &lt;a href= &#034;http://java.sun.com/javase/6/docs/technotes/guides/jweb/applet/liveconnect_support.html&#034; &gt;LiveConnect&lt;/a&gt;.  But apparently it works only if the applet extends &lt;tt&gt;java.applet.Applet&lt;/tt&gt;.  I extended &lt;tt&gt;javax.swing.JApplet&lt;/tt&gt; initially, thinking that JApplet is applet too.  But none of the Java methods on it was callable.  As soon as I changed to &lt;tt&gt;java.applet.Applet&lt;/tt&gt;, Java method calls from JavaScript worked.&lt;/li&gt;

&lt;li&gt;They worked in Firefox 3 and IE7, but not Google Chrome nor Safari.  I guess such is web programming.&lt;/li&gt;

&lt;li&gt;After all these fuss and trials and errors, once things worked as documented, it did feel fast and snappy.  The start up delay is not longer than that of a Flash animation or even AJAX controls.  &lt;span style=&#034;color:red&#034;&gt;Sun really did eliminate the Java/Applet start up disadvantage.&lt;/span&gt;&lt;/li&gt;

&lt;li&gt;As I modified the applet and jarred it up and uploaded it to the server, I have to fight the JRE cache on the browser side to load the new version of the jar file.  At one point, I removed the jar file from the server, restarted Tomcat, yet the browser still had the applet running, even after clicking on the reload button multiple times while the shift or control key was held down.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;For the curious, here is &lt;a href= &#034;http://www.weiqigao.com/blog/pages/return_of_the_applet.html&#034; &gt;the happy version of this blog&lt;/a&gt;. (Beware of Applet!  You&#039;ve been warned.)&lt;/p&gt;
        </description>
      
      
    
    
    
    <comments>http://www.weiqigao.com/blog/2008/10/29/this_applet_not_brought_to_you_by.html#comments</comments>
    <guid isPermaLink="true">http://www.weiqigao.com/blog/2008/10/29/this_applet_not_brought_to_you_by.html</guid>
    <pubDate>Wed, 29 Oct 2008 13:43:46 GMT</pubDate>
  </item>
  
  </channel>
</rss>

