📅  最后修改于: 2020-10-01 05:36:48             🧑  作者: Mango
java.applet.AppletContext类提供小程序之间的通信功能。我们通过HTML文件提供applet的名称。它提供了getApplet()方法,该方法返回Applet的对象。句法:
public Applet getApplet(String name){}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ContextApplet extends Applet implements ActionListener{
Button b;
public void init(){
b=new Button("Click");
b.setBounds(50,50,60,50);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
AppletContext ctx=getAppletContext();
Applet a=ctx.getApplet("app2");
a.setBackground(Color.yellow);
}
}