The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
You can deploy applets by using the runApplet
function of the
Deployment Toolkit script. The runApplet
function ensures that the required minimum version of the Java Runtime Environment (JRE) software exists on the client and then runs the applet. The runApplet
function generates an HTML <applet>
tag with the information provided.
You can deploy applets by specifying the deployment options as attributes and parameters of the <applet>
tag. You can also specify deployment options in a Java Network Launch Protocol (JNLP) file to take advantage of advanced features. See the
Java Network Launch Protocol topic for more information about this protocol.
If the client does not have the required minimum version of the JRE software, the Deployment Toolkit script redirects the browser to http://www.java.com
to allow users to download the latest JRE software. On some platforms, users might be redirected before they can view the web page containing the applet.
The parameters to the runApplet
function vary depending on whether you are using JNLP. Applets deployed by using JNLP can run only if the next generation Java Plug-in software exists on the client machine (the next generation Java Plug-in software was introduced in the Java Platform, Standard Edition 6 update 10 release).
The next section shows how to use the runApplet
function in the HTML page that will display the applet. The following usage scenarios are described:
jnlp_href
parameter to specify deployment options in a JNLP fileFunction signature: runApplet: function(attributes, parameters, minimumVersion)
Parameters:
attributes
– The names and values of the attributes of the generated <applet>
tagparameters
– The names and values of the <param>
tags in the generated <applet>
tagminimumVersion
– The minimum version of the JRE software that is required to run this appletUsage:
The attributes and parameters passed as name-value pairs are written out as attributes and nested <param>
tags in the generated <applet>
tag. Applets deployed in this manner can be run by the old Java Plug-in software.
// launch the Java 2D applet on JRE version 1.6.0 // or higher with one parameter (fontSize) <script src= "https://www.java.com/js/deployJava.js"></script> <script> var attributes = {code:'java2d.Java2DemoApplet.class', archive:'Java2Demo.jar', width:710, height:540}; var parameters = { fontSize:16, permissions:'sandbox' }; var version = '1.6'; deployJava.runApplet(attributes, parameters, version); </script>
Open
in a browser to view the Java2D applet.DeployUsingNameValuePairs.html
jnlp_href
parameter to specify deployment options in a JNLP file
The attributes and parameters (jnlp_href
in this case) passed as name-value pairs are written out as attributes and nested <param>
tags in the generated <applet>
tag. Applets deployed in this manner can be run by the next generation Java Plug-in software only. It is better to specify the applet's width and height as attributes as follows:
<script src="https://www.java.com/js/deployJava.js"></script> <script> var attributes = { code:'java2d.Java2DemoApplet', width:710, height:540 }; var parameters = { jnlp_href: 'java2d.jnlp' }; deployJava.runApplet(attributes, parameters, '1.6'); </script>
Open
in a browser to view the Java2D applet.DeployUsingJNLP.html
Applets deployed by using JNLP will run only if end users have the next generation Java Plug-in software running on their browsers. If you would like your applet to run on the old Java Plug-in software also, specify deployment options using attribute and parameter name-value pairs as well as a JNLP file.
<script src="https://www.java.com/js/deployJava.js"></script> <script> var attributes = {code:'java2d.Java2DemoApplet.class', archive:'Java2Demo.jar', width:710, height:540}; var parameters = { fontSize:16, jnlp_href:'java2d.jnlp' }; var version = '1.6' ; deployJava.runApplet(attributes, parameters, version); </script>
The following guidelines are helpful if some deployment options have different values in the attribute name-value pairs and in the JNLP file:
width
and height
as attribute name-value pairs (not in the JNLP file).image
and boxbgcolor
as parameter name-value pairs (not in the JNLP file). These parameters are needed early on in the applet startup process.codebase
attribute empty or specify an absolute URL. When the codebase
attribute is left empty, it defaults to the directory containing the JNLP file.code
, codebase
, and archive
attributes are taken from the JNLP file. If these attributes are also specified separately as attribute name-value pairs, the attribute name-value pairs are ignored.Open
in a browser to view the Java2D applet.DeployUsingNameValuePairsAndJNLP.html
Download source code for the Run Applet example to experiment further.