${log.root}/lowem.log
Inflation, Investing and Everything


All | Energy | Java | Tech | Musings | Env | Biz

AddThis Feed Button
20050514 Saturday May 14, 2005

Java applets and the accursed object tag

Recently, I encountered a problem with a Java applet not being able to load up (init, start, whatever). Upon closer inspection it turned out that the web page author had hardcoded a clsid for the specific JRE version 1.4.2_05 onto the object tag. After asking around, I was advised to install the 1.4.2_05 JRE (you know, *shrug* "it worked for me").

Wasn't too happy with it, though it did work, after going to the Java control panel and pointing it to 1.4.2_05 instead of my 1.4.2_08 which I have already installed.

Not being a particularly front-end kind of person (usually dwelling in the deep, dark shadows of the Sun Java JDK), I wondered what the fuss was about. Putting on the black hat which I wear occasionally (for these occasions), I came up with the following little hack that successfully tricked my IE into invoking my 1.4.2_08 JRE on that page. Just need to create some file, say, jre.reg, paste in the following, execute and voila :

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{CAFEEFAC-0014-0002-0005-ABCDEFFEDCBA}]
@="Java Plug-in 1.4.2_05"

[HKEY_CLASSES_ROOT\CLSID\{CAFEEFAC-0014-0002-0005-ABCDEFFEDCBA}\InprocServer32]
@="C:\\Program Files\\Java\\j2re1.4.2_08\\bin\\npjpi142_08.dll"
"ThreadingModel"="Apartment"

[HKEY_CLASSES_ROOT\CLSID\{CAFEEFAC-0014-0002-0005-ABCDEFFEDCBB}]
@="Java Plug-in 1.4.2_05 <applet> redirector"

[HKEY_CLASSES_ROOT\CLSID\{CAFEEFAC-0014-0002-0005-ABCDEFFEDCBB}\InprocServer32]
@="C:\\Program Files\\Java\\j2re1.4.2_08\\bin\\npjpi142_08.dll"
"ThreadingModel"="Apartment"

Now that was really quite darn ugly, but it did work, didn't it. Now, look, I've been kinda out of the GUI front-end business since, oh, say, about 1994 when I coded some of the first web pages for my university's computer club and anime club, but weren't applets supposed to stick to, you know, the APPLET tag?

Okay, it seems that some parts of the world have "moved on", not necessarily for the better, to using the OBJECT tag. And what a mess that is. The best way is to show some examples :

This should work in all browsers :

<applet code="Clock3D.class" archive="3dclock.zip" width=150 height=80>
  ... applet parameters omitted
</applet>

This will work only in Internet Explorer. The magic CLSID key invokes whichever is the latest installed JRE :

<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
  width="150" height="80">
  <param name="code" value="Clock3D">
  <param name="archive" value="3dclock.zip"/>
  ... applet parameters omitted
</object>

This will work only in Internet Explorer and only if you have the specific 1.4.2_08 JRE installed :

<object classid="CAFEEFAC-0014-0002-0008-ABCDEFFEDCBA"
  width="150" height="80">
  <param name="code" value="Clock3D">
  <param name="archive" value="3dclock.zip"/>
  ... applet parameters omitted
</object>

This will work only in Internet Explorer and only if you have the specific 1.4.2_05 JRE installed (or 1.4.2_08 and my hack above) :

<object classid="CAFEEFAC-0014-0002-0005-ABCDEFFEDCBA"
  width="150" height="80">
  <param name="code" value="Clock3D">
  <param name="archive" value="3dclock.zip"/>
  ... applet parameters omitted
</object>

This will work in both Mozilla Firefox and IE *and* will use whatever is the latest JRE you have installed. This is sh** ugly code and if you insist on using the object tag, that's what you have to use :

This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.
<!--[if !IE]> Firefox and others will use outer object -->
<object classid="java:Clock3D.class"
    type="application/x-java-applet"
    archive="3dclock.zip"
    height="150" width="80">
      <param name="code" value="Clock3D"/>
      <param name="archive" value="3dclock.zip"/>
    ... applet parameters omitted
<!--<![endif]-->
<!-- MSIE (Microsoft Internet Explorer) will use inner object -->
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"
    height="150" width="80">
      <param name="code" value="Clock3D"/>
      <param name="archive" value="3dclock.zip"/>
      ... applet parameters omitted
  <strong>
  This browser does not have a Java Plug-in.
  <br/>
  <a href="http://java.sun.com/products/plugin/downloads/index.html">
  Get the latest Java Plug-in here.
  </a>
  </strong>
</object>
<!--[if !IE]> close outer object -->
</object>
<!--<![endif]-->

Conclusion - if you wish a hair-pulling time upon yourself, by all means, use the last approach. It'll work happily in both Mozilla Firefox and Internet Explorer, and you can strongly encourage hapless users who don't have a JRE at all to go get JRE 1.5.0 or something. *And* you get to use the all-mighty, all-entangling, <OBJECT> tag.

Me, I think I'll stick to <APPLET> if I need something simple and working for my own pages. You know, the KISS principle - Keep It Simple, Stupid!!!

By the way, the nice 3D clock applet shown above was written back in 1997 by this Bennet guy, who's apparently a Swiss.

See also :

1. Using applet, object and embed Tags (java.sun.com)
2. (Multiple Browser Supported) Java applet using XHTML 'object' tag (cs.fsu.edu/~steele)

(2005-05-14 23:22:55 SGT) [Java] Permalink


Your Ad Here


Most popular blog postings on lowem.log :

1. Singapore MRT rail network length to double by 2020
2. 2010 Nissan Leaf electric car specifications : 107hp, 24KWh lithium-ion batteries, 100-mile range
3. Live spot gold price quotes chart on COMEX
4. 2010 Toyota Prius specifications released : 50 mpg, 1.8L, 134hp, Ni-MH, solar roof option
5. AVG Anti-Virus Free Edition 2011 direct download link
6. Real-time live gold and silver price quotes chart on COMEX
7. Singapore electric vehicles : Government agencies EMA and LTA to study EV introduction
8. Book review : Shut Down by William Flynn

Featured articles on lowem.log :

1. Book review : Shut Down by William Flynn
2. Singapore electric cars testing starts with 9 electric vehicles
3. Honda, GS Yuasa JV to make lithium-ion batteries for 2010/2011 Honda Civic Hybrid
4. 2010 Honda Civic Hybrid preliminary specifications released
5. 2010 Honda CR-Z hybrid, 2010 Honda Fit/Jazz hybrid models confirmed
6. 2010 Toyota Prius specifications released : 50 mpg, 1.8L, 134hp, Ni-MH, solar roof option
7. NYMEX crude oil recovers from $32.40 low after 2.2 mbpd OPEC production cut announced
8. Singapore : Nuclear power not ruled out



search
sponsored links


bookmarks

about
my profile
contact me

blogroll
biow/ken/wenn
reviewem
dividend investing

sites
photo gallery
wiki

quotes
live oil prices
live gold prices

charts
live forex rates
live oil chart
live brent crude chart
live gold chart
live silver chart

historical
crude oil chart
gold chart
silver chart


navigation
decals

Click for Singapore, Singapore Forecast





rss feed for lowem.log

Get Firefox!

powered by
hosted by