当前位置: 技术问答>java相关
请大家帮帮忙吧
来源: 互联网 发布时间:2015-10-05
本文导语: 现有两个applet程序,请问如何才能实现在一个applet程序中调用另外一个程序。 thanks... waiting... | Have Applets on the same page communicate with each other [Applet1] import java.awt.*; public class Applet1 extends java.apple...
现有两个applet程序,请问如何才能实现在一个applet程序中调用另外一个程序。
thanks...
waiting...
thanks...
waiting...
|
Have Applets on the same page communicate with each other
[Applet1] import java.awt.*;
public class Applet1 extends java.applet.Applet {
TextField inputText;
Button b;
public void init() {
setLayout(new FlowLayout());
inputText = new TextField( "", 15 );
b = new Button("Send to Applet 2");
add(inputText);
add(b);
}
public boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
String textMsg = inputText.getText().trim();
Applet2 applet2 =
(Applet2)getAppletContext().getApplet("applet2");
if ( applet2 != null ) {
applet2.AppendText( textMsg );
return true;
}
else
return false;
}
return false;
}
[Applet2] import java.awt.*;
public class Applet2 extends java.applet.Applet {
TextArea textBox;
public void init() {
setLayout(new FlowLayout());
textBox = new TextArea( 5, 40 );
add( textBox );
}
public void AppendText( String msg ) {
String newLine = new String( "n" );
textBox.appendText( msg );
textBox.appendText( newLine );
}
}
[HTML]
[Applet1] import java.awt.*;
public class Applet1 extends java.applet.Applet {
TextField inputText;
Button b;
public void init() {
setLayout(new FlowLayout());
inputText = new TextField( "", 15 );
b = new Button("Send to Applet 2");
add(inputText);
add(b);
}
public boolean action(Event ev, Object arg) {
if (ev.target instanceof Button) {
String textMsg = inputText.getText().trim();
Applet2 applet2 =
(Applet2)getAppletContext().getApplet("applet2");
if ( applet2 != null ) {
applet2.AppendText( textMsg );
return true;
}
else
return false;
}
return false;
}
[Applet2] import java.awt.*;
public class Applet2 extends java.applet.Applet {
TextArea textBox;
public void init() {
setLayout(new FlowLayout());
textBox = new TextArea( 5, 40 );
add( textBox );
}
public void AppendText( String msg ) {
String newLine = new String( "n" );
textBox.appendText( msg );
textBox.appendText( newLine );
}
}
[HTML]