Applet类最早jdk1.0
Applet类继承自Pancel
1.构造器方法
public Applet() throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
}
new 一个Applet。如果此环境不依赖于显示,鼠标,键盘就会抛HeadlessException异常 (在不支持键盘、显示器或鼠标的环境中调用依赖于键盘、显示器或鼠标的代码时引发)
2.私有属性
transient private AppletStub stub;
一个不可序列化的私有属性,启动使用
3.私有属性,序列化id
private static final long serialVersionUID = -5836846270535785031L;
4.私有方法
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException, HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
s.defaultReadObject();
}
从对象输入流中读取applet.实现就是环境不对抛出HeadlessException。然后调用ObjectInputStream的默认方法
5.公共不可变 set方法
public final void setStub(AppletStub stub) {
if (this.stub != null) {
SecurityManager s = System.getSecurityManager();
if (s != null) {
s.checkPermission(new AWTPermission("setAppletStub"));
}
}
this.stub = stub;
}
6.公共判断方法
public boolean isActive() {
if (stub != null) {
return stub.isActive();
} else { // If stub field not filled in, applet never active
return false;
}
}
判断 Applet是否处于活跃状态。调用start()方法之前变为活跃的,调用stop()方法之前变为非活跃的
7.公共方法
public URL getDocumentBase() {
return stub.getDocumentBase();
}
获取文档地址
8.公共方法
public URL getCodeBase() {
return stub.getCodeBase();
}
获取code地址
9.公共方法
public String getParameter(String name) {
return stub.getParameter(name);
}
获取html标记中指定参数的值(类型request.getParameter)
10.公共方法
public AppletContext getAppletContext() {
return stub.getAppletContext();
}
获取AppletContext
11.公共方法
public void resize(int width, int height) {
Dimension d = size();
if ((d.width != width) || (d.height != height)) {
super.resize(width, height);
if (stub != null) {
stub.appletResize(width, height);
}
}
}
重写applet 的大小
12.公共方法
public void resize(Dimension d) {
resize(d.width, d.height);
}
同上
13.重写方法
@Override
public boolean isValidateRoot() {
return true;
}
如果对象是验证根。返回true
14.公共方法
public void showStatus(String msg) {
getAppletContext().showStatus(msg);
}
通知用户当前状态
15.公共方法
public Image getImage(URL url) {
return getAppletContext().getImage(url);
}
通过地址获取图片
16.公共方法
public Image getImage(URL url, String name) {
try {
return getImage(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
通过地址和名称获取图片
17.静态不可变方法
public final static AudioClip newAudioClip(URL url) {
return new sun.applet.AppletAudioClip(url);
}
获取AudioClip通过url地址
18.公共方法
public AudioClip getAudioClip(URL url) {
return getAppletContext().getAudioClip(url);
}
获取AudioClip通过url,(与上相比实现不同,而且一个是静态不可变。一个是调用)
19.公共方法
public AudioClip getAudioClip(URL url, String name) {
try {
return getAudioClip(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
获取AudioClip通过url和name
20.公共方法。
public String getAppletInfo() {
return null;
}
一个需要被重写的方法。返回applet的作者,版本,版权信息。
21.公共方法
public Locale getLocale() {
Locale locale = super.getLocale();
if (locale == null) {
return Locale.getDefault();
}
return locale;
}
获取applet的local(区域)
22.公共方法
public String[][] getParameterInfo() {
return null;
}
返回此applet的可被理解的信息。如下形式
String pinfo[][] = { {"fps", "1-10", "frames per second"}, {"repeat", "boolean", "repeat image loop"}, {"imgs", "url", "images directory"} };
23.公共方法
public void play(URL url) {
AudioClip clip = getAudioClip(url);
if (clip != null) {
clip.play();
}
}
按指定的绝对URL播放音频剪辑。如果找不到音频剪辑,则什么也不会发生。
24.公共方法
public void play(URL url, String name) {
AudioClip clip = getAudioClip(url, name);
if (clip != null) {
clip.play();
}
}
播放给定URL和与其相关的说明符的音频剪辑。如果找不到音频剪辑,则什么也不会发生。
25.初始化方法
public void init() {
}
26.启动方法
public void start() {
}
27.停止方法
public void stop() {
}
28。销毁方法
public void destroy() {
}
29.AccessibleContext对象
AccessibleContext accessibleContext = null;
默认为null
30.公共方法
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleApplet();
}
return accessibleContext;
}
获取上下文对象。有返回,无的话new一个新的。单例懒加载
31.内部类
protected class AccessibleApplet extends AccessibleAWTPanel {
private static final long serialVersionUID = 8127374778187708896L;
/**
* Get the role of this object.
*
* @return an instance of AccessibleRole describing the role of the
* object
*/
public AccessibleRole getAccessibleRole() {
return AccessibleRole.FRAME;
}
/**
* Get the state of this object.
*
* @return an instance of AccessibleStateSet containing the current
* state set of the object
* @see AccessibleState
*/
public AccessibleStateSet getAccessibleStateSet() {
AccessibleStateSet states = super.getAccessibleStateSet();
states.add(AccessibleState.ACTIVE);
return states;
}
}
这个类提供了适合applet用户界面元素的Java可访问性API的实现。