Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

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. Syntax:

  1. public Applet getApplet(String name){}

Example of Applet Communication

  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. public class ContextApplet extends Applet implements ActionListener{
  5. Button b;
  6. public void init(){
  7. b=new Button(“Click”);
  8. b.setBounds(50,50,60,50);
  9. add(b);
  10. b.addActionListener(this);
  11. }
  12. public void actionPerformed(ActionEvent e){
  13. AppletContext ctx=getAppletContext();
  14. Applet a=ctx.getApplet(“app2”);
  15. a.setBackground(Color.yellow);
  16. }
  17. }

myapplet.html

  1. <html>
  2. <body>
  3. <applet code=“ContextApplet.class” width=“150” height=“150” name=“app1”>
  4. </applet>
  5. <applet code=“First.class” width=“150” height=“150” name=“app2”>
  6. </applet>
  7. </body>
  8. </html>

Comments

comments