Solved

simple applet and java exe questions

Posted on 2003-11-13
4
741 Views
Last Modified: 2013-11-23
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
Comment
Question by:aj_2003
  • 3
4 Comments
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9741220
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
 
LVL 2

Accepted Solution

by:
SuperKarateMonkey earned 50 total points
ID: 9741280
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
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9741286
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
 

Author Comment

by:aj_2003
ID: 9748389
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
return in catch statement 1 40
parentbit challenge 3 52
create a gui in perl 3 46
@SBGen Method 3 25
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now