public class Applet extends Applet implements ActionListener { TextField textField;
Button button;
public void init() { textField = new TextField("", 25);
button = new Button("pass to Applet2");
button.addActionListener(this);
add(textField);
add(button); }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() instanceof Button) { String textMsg = textField.getText().trim();
Applet2 applet2 = (Applet2) getAppletContext().getApplet("Applet2"); if (applet2 != null) { applet2.add(textMsg); } else { System.out.println("Applet2 not found"); }
}
}
}
import java.applet.Applet; import java.awt.*;
public class Applet2 extends Applet { public void init() { Label label = new Label("Message
from 1st Applet"); add(label); TextField textfield = new TextField(50); add(textfield); String s = getDocumentBase().toString(); String s1 = s.substring(s.indexOf('?') + 1); s1 = s1.substring("message=".length()); s1 = s1.replace('+', ' '); textfield.setText(s1); }
}