Applet Communication
java.applet.AppletContext
class provides the facility of communication between applets. We provide the
name of applet through the HTML file. It provides getApplet() method that
returns the object of Applet.
Fig: Applet Communication |
Syntax:
public Applet getApplet(String name){}
Example of Applet Communication
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);
}
}
myapplet.html
<html>
<body>
<applet code="ContextApplet.class" width="150" height="150" name="app">
</applet>
<applet code="First.class" width="150" height="150" name="app2">
</applet>
</body>
</html>
No comments:
Post a Comment