public class InterApplet1 extends Applet implements ActionListener { TextField textField;
Button button;
public void init() { textField = new TextField("", 25);
button = new Button("pass to InterApplet2");
button.addActionListener(this);
add(textField);
add(button); }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() instanceof Button) { String textMsg = textField.getText().trim();
InterApplet2 InterApplet2 = (InterApplet2) getAppletContext() .getApplet("InterApplet2"); if (InterApplet2 != null) { InterApplet2.add(textMsg); } else { System.out.println("InterApplet2 not found"); }
}
}
}
import java.applet.Applet; import java.awt.*;
public class InterApplet2 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); }
}