public class GetApplet_AppletContext extends Applet implements ActionListener { TextField textField;
Button button;
public void init() { textField = new TextField("", 25);
button = new Button("pass to GetApplet2");
button.addActionListener(this);
add(textField);
add(button); }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() instanceof Button) { String textMsg = textField.getText().trim();
GetApplet2 GetApplet2 = (GetApplet2) getAppletContext().getApplet( "GetApplet2"); if (GetApplet2 != null) { GetApplet2.add(textMsg); } else { System.out.println("GetApplet2 not found"); }
}
}
}
import java.applet.Applet; import java.awt.*;
public class GetApplet2 extends Applet { TextArea textArea;
public void init() { textArea = new TextArea(7,
30); add(textArea); }
public void add(String msg) { textArea.append(msg); textArea.append("\n"); }
}