Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 750
  • Last Modified:

simple applet and java exe questions

Hi, I have 2 questions.

1)
I made an applet. The applet tag in the html file looks like the following:

"<APPLET CODE="Applet.class" width="800" height="500">
</APPLET>"

How do I change the above tag so that when someone tries to run the applet on a machine that doesn't have Java, the browser goes and downloads the java plug-in automatically?

2)
I used some program to convert a class/jar file into an exe. It runs fine on a computer with a Java Runtime environment. But when I  tried to run it on a computer that does not have Java, it doesn't run. Isn't the whole point of an executable to be able to run independantly? Is there a way I can accomplish this?

Thanks
AJ
0
aj_2003
Asked:
aj_2003
  • 3
1 Solution
 
SuperKarateMonkeyCommented:
First of all, MS bundles their Java plug-in with IE, so that covers an awful lot of your codebase.  However, if you really want to force the user to dynamically download the proper Sun Java plug-in, you can do so with the <OBJECT>,(for IE,) and <EMBED>, (for Netscape,) tags, instead of the <APPLET> tag, though only <APPLET> is universally supported:

For IE:

<OBJECT classid=="clsid:CAFEEFAC-0014-0002-0000-ABCDEFFEDCBA"
              width="800" height="500"
              codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab#Version=1,4,2,0">

    <PARAM name="code" value="Applet.class" />
    <PARAM name="type" value="application/x-java-applet;jpi-version=1.4.2">
</OBJECT>

This will instruct IE to go get the SUN Java Plug-In if the version specified, (in this case, 1.4.2,) is greater than the available version, of if no version is available at all.  Note that some of the attributes from the <APPLET> tag are retained AS ATTRIBUTES in the <OBJECT> tag, such as height and width, whilst others are converted into <PARAM name="attributeName" value="attributeValue" /> format.  ALSO IMPORTANT:  The value of the codebase ATTRIBUTE of the <OBJECT> tag has NOTHING to do with the applet codebase.  It's the location that IE can download the .cab file for the Java Plug-In from.  If you want to specify an <APPLET> codebase, use the <PARAM name="codebase" ... /> format.

A similar procedure is used with the <EMBED> tag for Netscape.  You'll have to include both if you need to support both.  God only knows what the other browsers, such as Opera, Lynx, and Konqueror support.  You'll have to check their documentation, as well as the W3C, who defined the <OBJECT> and <EMBED> tags.  As for Mozilla, the most popular Non IE/Netscape browser, I suspect it basically behaves like Netscape, since they share much of the same code tree.
0
 
SuperKarateMonkeyCommented:
For your 2nd question:

You're not truly compiling to a .exe file.  This could be because of 2 possible reasons:

1.  Your program is crap -- All it's doing is wrapping up your class(es) into a jar file, (let's call it youjarfile.jar,) and then wrapping that jar file in a thin .exe that simply calls the command line:

javaw -jar yourjarfile.jar

2.  Your program isn't quite crap, but isn't configured right -- It still wants the .exe file to support some of the cool java features, such as dynamic class loading, (do you have those in your classes?)  It therefore involves the JRE to assist with that.

That's not really the problem, though.  You shouldn't be compiling to a .exe file.  Why use java if you're going to give up all it's cool features? 99% of the time, it's enough to jar up your classes into an executable .jar file and include the parameter Main-class in the manifest, since by default, anyone with the JRE or JDK installed will be able to handle that file:  The installer creates the file association in windows that causes executable jar files to be handled via the command:

javaw -jar "%1"

 If you REALLY REALLY need to compile to a .exe, however, there are other options.  I wonder what application you're using right now.  If you didn't pay much for it it's probably not a true native compiler.  Check these links out for information on native compilation:

http://www-106.ibm.com/developerworks/library/j-native.html
http://www.javaworld.com/javaworld/javaqa/2001-06/02-qa-0615-exe.html
0
 
SuperKarateMonkeyCommented:
Oh, by the way, in response to your first question, there's an excellent resource on the applet tagging conventions here:

http://java.sun.com/j2se/1.4.2/docs/guide/plugin/developer_guide/using_tags.html
0
 
aj_2003Author Commented:
You were right...the program i downloaded simply wrapped a jar into an exe and thus needed a Java runtime environment.

Thanks for your sources about native compilers. I have never used visual age before but we have a license for it, so I'll look into how to use it to do this.

Thanks for your help.
AJ
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now