# Applet 入门

> 原文： [https://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html](https://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html)

接下来显示的 HelloWorld applet 是一个显示字符串“Hello World”的 Java 类。

<noscript>A browser with JavaScript enabled is required for this page to operate properly.</noscript>

* * *

**Note:**  If you don't see the example running, you might need to enable the JavaScript interpreter in your browser so that the Deployment Toolkit script can function properly.

* * *

以下是 HelloWorld applet 的源代码：

```
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");
        }
    }
}

```

像这样的 applet 通常由浏览器中的 _Java Plug-in_ 软件管理和运行。

[下载 _Hello World_ 示例的源代码](examplesIndex.html#HelloWorld)进行进一步实验。