The Java Tutorials have been written for JDK 8.Java教程是为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.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
You can deploy applets by using the 可以使用部署工具包脚本的runApplet
function of the Deployment Toolkit script. runApplet
函数部署小程序。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. runApplet
函数确保客户端上存在所需的Java运行时环境(JRE)软件的最低版本,然后运行小程序。The runApplet
function generates an HTML <applet>
tag with the information provided.runApplet
函数生成一个带有所提供信息的HTML<applet>
标记。
You can deploy applets by specifying the deployment options as attributes and parameters of the 通过将部署选项指定为<applet>
tag. <applet>
标记的属性和参数,可以部署applet。You can also specify deployment options in a Java Network Launch Protocol (JNLP) file to take advantage of advanced features. 您还可以在Java网络启动协议(JNLP)文件中指定部署选项,以利用高级功能。See the Java Network Launch Protocol topic for more information about this protocol.有关该协议的更多信息,请参阅Java网络启动协议主题。
If the client does not have the required minimum version of the JRE software, the Deployment Toolkit script redirects the browser to 如果客户端没有所需的JRE软件最低版本,部署工具包脚本会将浏览器重定向到http://www.java.com
to allow users to download the latest JRE software. http://www.java.com
以允许用户下载最新的JRE软件。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. runApplet
函数的参数根据您是否使用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).使用JNLP部署的小程序只有在客户机上存在下一代Java插件软件时才能运行(下一代Java插件软件是在Java平台的Standard Edition 6 update 10发行版中引入的)。
The next section shows how to use the 下一节将展示如何在显示小程序的HTML页面中使用runApplet
function in the HTML page that will display the applet. runApplet
函数。The following usage scenarios are described:描述了以下使用场景:
jnlp_href
parameter to specify deployment options in a JNLP filejnlp_href
参数在jnlp文件中指定部署选项Function signature:函数签名: runApplet: function(attributes, parameters, minimumVersion)
Parameters:参数:
attributes
– <applet>
tag<applet>
标记的属性的名称和值parameters
– <param>
tags in the generated <applet>
tag<applet>
标记中<param>
标记的名称和值minimumVersion
– Usage:用法:
The attributes and parameters passed as name-value pairs are written out as attributes and nested 作为名称-值对传递的属性和参数将作为属性和嵌套的<param>
tags in the generated <applet>
tag. <param>
标记写入生成的<applet>
标记中。Applets deployed in this manner can be run by the old Java Plug-in software.以这种方式部署的小程序可以由旧的Java插件软件运行。
// 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 在浏览器中打开DeployUsingNameValuePairs.html
in a browser to view the Java2D applet.DeployUsingNameValuePairs.html
以查看Java2D小程序。
jnlp_href
parameter to specify deployment options in a JNLP file jnlp_href
参数在jnlp文件中指定部署选项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. jnlp_href
)将作为属性和嵌套的<param>
标记写入生成的<applet>
标记中。Applets deployed in this manner can be run by the next generation Java Plug-in software only. 以这种方式部署的小程序只能由下一代Java插件软件运行。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 在浏览器中打开DeployUsingJNLP.html
in a browser to view the Java2D applet.DeployUsingJNLP.html
以查看Java2D小程序。
Applets deployed by using JNLP will run only if end users have the next generation Java Plug-in software running on their browsers. 使用JNLP部署的小程序只有在最终用户的浏览器上运行下一代Java插件软件时才会运行。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.如果希望小程序也在旧的Java插件软件上运行,请使用属性和参数名称-值对以及JNLP文件指定部署选项。
<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:如果某些部署选项在属性名称-值对和JNLP文件中具有不同的值,则以下指导原则非常有用:
width
and height
as attribute name-value pairs (not in the JNLP file).width
和height
指定为属性名称-值对(不在JNLP文件中)。image
and boxbgcolor
as parameter name-value pairs (not in the JNLP file). image
和boxbgcolor
等参数指定为参数名称-值对(不在JNLP文件中)。codebase
attribute empty or specify an absolute URL. codebase
属性保留为空或指定一个绝对URL。codebase
attribute is left empty, it defaults to the directory containing the JNLP file.codebase
属性为空时,它默认为包含JNLP文件的目录。code
, codebase
, and archive
attributes are taken from the JNLP file. code
、codebase
和archive
属性的值取自JNLP文件。Open 在浏览器中打开DeployUsingNameValuePairsAndJNLP.html
in a browser to view the Java2D applet.DeployUsingNameValuePairsAndJNLP.html
以查看Java2D小程序。
Download source code for the Run Applet example to experiment further.下载Run Applet示例的源代码以进行进一步实验。