Java 教程是为 JDK 8 编写的。本页中描述的示例和实践未利用在后续版本中引入的改进。
A default loading screen is displayed when an applet is being loaded in the web page. You can display a customized splash screen by specifying the following parameters when you deploy the applet:
image
- the image to be displayed in the splash screenboxbgcolor
- the background color of the area in which the applet will be displayedboxborder
- whether the applet should have a border; defaults to true
centerimage
- the position of the image; defaults to false
The splash screen can display a static image or an animated gif.
The code snippet from
shows how to customize the splash screen to display an animation of the Duke, the Java mascot.AppletPage.html
<script src="https://www.java.com/js/deployJava.js"></script> <script> var attributes = {code:'SwingSet2Applet.class', archive:'SwingSet2.jar', width:695, height:525} ; <!-- customize splash screen display options --> var parameters = {jnlp_href: 'SwingSet2.jnlp', image: 'dukeanimated.gif', boxbgcolor: 'cyan', boxborder: 'true', centerimage: 'true' }; deployJava.runApplet(attributes, parameters, '1.6'); </script>
Open
in a browser to view the splash screen when the SwingSet2 Demo applet is loaded. If you've clicked this link before and viewed the SwingSet2 Demo applet, make sure to clear your cache using the Java Control Panel. You may not see the splash screen if the applet loads quickly.AppletPage.html
See the Displaying a Customized Loading Progress Indicator topic for information about displaying a customized loading progress indicator when the applet's resources are being downloaded.
Download source codefor the Customizing Splash Screen example to experiment further.