Java Example Program / Sample Source Code
import java.applet.Applet;
import java.awt.Button;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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 { TextArea textArea; public void init() { textArea = new TextArea(7,
30); add(textArea); } public void add(String msg) { textArea.append(msg); textArea.append("\n"); }
} |