The Artima Developer Community
Sponsored Link

Java Buzz Forum
This Applet Not Brought To You By...

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Weiqi Gao

Posts: 1808
Nickname: weiqigao
Registered: Jun, 2003

Weiqi Gao is a Java programmer.
This Applet Not Brought To You By... Posted: Oct 29, 2008 8:42 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Weiqi Gao.
Original Post: This Applet Not Brought To You By...
Feed Title: Weiqi Gao's Weblog
Feed URL: http://www.weiqigao.com/blog/rss.xml
Feed Description: Sharing My Experience...
Latest Java Buzz Posts
Latest Java Buzz Posts by Weiqi Gao
Latest Posts From Weiqi Gao's Weblog

Advertisement

... a buggy JavaScript file.

([Note] The following would have been a charming little blog entry with a small Java applet that warms people's hearts, had I not ran into some troubles that made the whole thing, eh, what shall I say, a little annoying.)

Along with Java 6 Update 10, released 14 days ago, comes a JavaScript file deployJava.js hosted at http://java.sun.com, that, among other things, helps in deploying Java applets.

Here's a little applet, deployed according to this advice:

(Source of a would-be applet follows)

<div style="margin-left:3em">
<script src="http://java.com/js/deployJava.js"></script>
<script>
    var attributes =
        {id:'squareApplet',
        codebase:'http://www.weiqigao.com/blog/files',
        code:'com.weiqigao.square.SquareApplet.class',
        archive:'square.jar',
        width: 100, height:100};
    var parameters = {color: 'red'};
    var version = '1.6' ;
    deployJava.runApplet(attributes, parameters, version);
</script></applet>
</div>

<script>
  function toBlue() {
    document.squareApplet.toBlue();
  }

  function toRed() {
    document.squareApplet.toRed();
  }
</script>

<p>And you can change its color to <a href=  "javascript:toBlue()"
>blue</a> and <a href= "javascript:toRed()" >back</a>.</p>

Here's the issues I had with this setup:

  • I don't have Java plug-in on my 64-bit Debian GNU/Linux machine. This causes the above script to auto-redirect to Java Downloads for Linux. But it forgot one thing: there isn't a Java plug-in for 64-bit Linux to download. In the mean time, I can't even go back to the blog entry to edit it.
  • 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.
  • Luckily, Google Chrome was more tolerant, and I was able to resume my editing. I added the closing </applet> tag after the JavaScript code to make it work in Firefox 3 and IE7.
  • One thing I want to experiment with is the revived LiveConnect. But apparently it works only if the applet extends java.applet.Applet. I extended javax.swing.JApplet initially, thinking that JApplet is applet too. But none of the Java methods on it was callable. As soon as I changed to java.applet.Applet, Java method calls from JavaScript worked.
  • They worked in Firefox 3 and IE7, but not Google Chrome nor Safari. I guess such is web programming.
  • 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. Sun really did eliminate the Java/Applet start up disadvantage.
  • 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.

For the curious, here is the happy version of this blog. (Beware of Applet! You've been warned.)

Read: This Applet Not Brought To You By...

Topic: Java Performance News September 2008 Previous Topic   Next Topic Topic: Reinventing the Wheel to Run Myself Over

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use