日期:2014-05-20 浏览次数:20638 次
// AppletTalkA.java import java.awt.*; import java.applet.*; import java.awt.event.*; public class AppletTalkA extends Applet { Button sendB; TextField mesgField; public void init() { mesgField=new TextField(30); sendB=new Button("Send"); sendB.addActionListener(this);//编译不通过 } public void actionPerformed(ActionEvent e) { if(e.getSource()==sendB){ String mesg=mesgField.getText(); AppletTalkB receiver=(AppletTalkB)getAppletContext().getApplet("receiver"); if(receiver!=null) receiver.getMessage(mesg); mesgField.setText(""); } } } // AppletTalkB.java import java.applet.*; import java.awt.*; import java.awt.event.*; public class AppletTalkB extends Applet{ TextArea mesgArea; public void init(){ mesgArea=new TextArea(10,30); } public void getMessage(String mesg){ mesgArea.append(mesg+"\n"); } }