📄 oneapplet.java
字号:
package twoappletcom;import java.awt.*;import java.awt.event.*;import java.applet.*;/** * Title: Web页内两个Applet通信 * Description: 在同一网页中建立两个Applet的通信。 * Copyright: Copyright (c) 2002 * Company: 北京师范大学计算机系 * @author 孙一林 * @version 1.0 */public class OneApplet extends Applet { TextField tf = new TextField("AnotherApplet,能收到信息了吗?",20); // 定义文本框 Button b = new Button("发送到AnotherApplet"); // 定义发送按钮 public void init() { setLayout(new FlowLayout()); add(tf); add(b); } public boolean action(Event ev, Object obj){ // 处理按钮事件 if(ev.target instanceof Button){ String msg = tf.getText(); AnotherApplet anotherApplet = (AnotherApplet)getAppletContext().getApplet("AnotherApplet"); if(anotherApplet != null){ anotherApplet.AppendText(msg); // 调用anotherApplet中的方法 return true; } else{ tf.setText("没有找到AnotherApplet"); return false; } } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -