1 一个简单的Applet
import java.awt.*;
import javax.swing.*;
/**
1. @version 1.24 2015-06-12
2. @author Cay Horstmann
*/
public class NotHelloWorld extends JApplet
{
public void init()
{
EventQueue.invokeLater(() -> {
JLabel label = new JLabel("Not a Hello, World applet",
SwingConstants.CENTER);
add(label);
});
}
}
- 编译为class文件
- 打包成JAR文件
- 创建HTML文件,告诉浏览器装载这个文件和界面大小。
<applet class="applet/NotHelloWorld.class" archive="NotHelloWorld.jar" width="300" height="300">
</applet>
appletviewer NotHelloWorldApplet.html
2 applet标签和它的属性
3 使用参数想applet传递信息
<applet code="FontParamApplet.class" ...>
<param name="font" value="Helvetica"/>
</applet>
public class FontParamApplet extends JApplet
{
public void init()
{
String fontName = getParameter("font");
. . .
}
. . .
}
4 接受图片和音频文件
Image cat = getImage(getDocumentBase(), "images/cat.gif");
AudioClip meow = getAudioClip(getDocumentBase(), "audio/meow.au");
play(getDocumentBase(), "audio/meow.au");
5 Applet环境
6 Applet间的交互
<applet code="Chart.class" width="100" height="100" name="Chart1">
Applet chart1 = getAppletContext().getApplet("Chart1")
7 在浏览器中显示信息
8 沙箱
9 签名代码