|
Have Applets on different frames communicates with each other |
|
|
It is possible to share data between different applets via static variables. The following code snippets shows an example of this:
[HTML (main.html)]
<HTML><HEAD></HEAD>
<FRAMESET COLS="50%,*">
<FRAME SRC="f1.html" NAME="f1">
<FRAME SRC="f2.html" NAME="f2">
</FRAMESET>
</HEAD>
[HTML (f1.html AND f2.html)]
<HTML><HEAD></HEAD>
<BODY>
<APPLET CODE="app.class"
NAME="app1"
HEIGHT=200
WIDTH=200>
</APPLET>
</BODY></HTML>
[Java source (app.java)]
import java.awt.*;
import java.applet.*;
public class app extends Applet {
TextField tf;
Button a,b;
public void init() {
setLayout(new FlowLayout());
a = new Button("Send");
b = new Button("Receive");
add(a);
add(b);
tf = new TextField(20);
add(tf);
}
public boolean action(Event e, Object o) {
if (e.target instanceof Button) {
if (e.target == a) {
StaticMessage.message = tf.getText();
}
if (e.target == b) {
tf.setText(StaticMessage.message);
}
return true;
}
return false;
}
}
class StaticMessage {
public static String message = "";
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.