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 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 { TextArea textArea; public void init() { textArea = new TextArea(7,
30); add(textArea); } public void add(String msg) { textArea.append(msg); textArea.append("\n"); }
} |