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发行说明。
Every Java applet must define a subclass of the 每个Java小程序必须定义Applet
or JApplet
class. Applet
子类或JApplet
类的子类。In the Hello World applet, this subclass is called 在Hello World小程序中,此子类称为HelloWorld
. HelloWorld
。The following is the source for the 以下是HelloWorld
class.HelloWorld
类的源代码。
import javax.swing.JApplet; import javax.swing.SwingUtilities; import javax.swing.JLabel; public class HelloWorld extends JApplet { //Called when this applet is loaded into the browser. public void init() { //Execute a job on the event-dispatching thread; creating this applet's GUI. try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { JLabel lbl = new JLabel("Hello World"); add(lbl); } }); } catch (Exception e) { System.err.println("createGUI didn't complete successfully"); } } }
Java applets inherit significant functionality from the Java小程序继承了Applet
or JApplet
class, including the capabilities to communicate with the browser and present a graphical user interface (GUI) to the user.Applet
或JApplet
类的重要功能,包括与浏览器通信和向用户显示图形用户界面(GUI)的功能。
An applet that will be using GUI components from Swing (Java's GUI toolkit) should extend the 将使用Swing(Java的GUI工具包)GUI组件的小程序应该扩展javax.swing.JApplet
base class, which provides the best integration with Swing's GUI facilities.javax.swing.JApplet
基类,该基类提供了与Swing GUI工具的最佳集成。
JApplet
provides a root pane, which is the same top-level component structure as Swing's JFrame
and JDialog
components, whereas Applet
provides just a basic panel. JApplet
提供了一个根窗格,它与Swing的JFrame
和JDialog
组件具有相同的顶级组件结构,而Applet
只提供了一个基本面板。See How to Use Root Panes for more details on how to use this feature.有关如何使用此功能的详细信息,请参阅如何使用根窗格。
An applet can extend the 当小程序不使用Swing的GUI组件时,它可以扩展java.applet.Applet
class when it does not use Swing's GUI components.java.applet.Applet
类。