[Java] applet程序之间的通信 →→→→→进入此内容的聊天室

来自 , 2019-12-11, 写在 Java, 查看 127 次.
URL http://www.code666.cn/view/8d317bdc
  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.util.Enumeration;
  5.  
  6. public class GetApplets extends Applet implements ActionListener {
  7.         private TextArea textArea; // 声明一个TextArea
  8.         private String newline;
  9.  
  10.         public void init() {
  11.                 Button b = new Button("Click to call getApplets()");
  12.                 b.addActionListener(this);
  13.                 setLayout(new BorderLayout());
  14.  
  15.                 add("North", b);
  16.                 textArea = new TextArea(5, 40);
  17.                 textArea.setEditable(false);
  18.                 add("Center", textArea);
  19.                 newline = System.getProperty("line,separator");
  20.                 // 取得系统当前的换行符
  21.         }
  22.  
  23.         public void actionPerformed(ActionEvent event) {
  24.                 /* Button b点击后的事件处理函数 */
  25.                 printApplets();
  26.         }
  27.  
  28.         public String getAppletInfo() {
  29.                 return "GetApplets by Dong.li";
  30.         }
  31.  
  32.         public void printApplets() {
  33.                 Enumeration e = getAppletContext().getApplets();
  34.                 /* 得到当前网页所有的Applet对象 */
  35.                 textArea.append("Results of getApplets():" + newline);
  36.                 while (e.hasMoreElements()) {
  37.                         Applet applet = (Applet) e.nextElement();
  38.                         String info = ((Applet) applet).getAppletInfo();
  39.                         /* 逐个取得当前网页Applet对象的信息 */
  40.                         if (info != null) {
  41.                                 textArea.append("-" + info + newline);
  42.                                 /* 在textArea中输出网页所有Applet的信息 */
  43.                         } else {
  44.                                 textArea.append("-" + applet.getClass().getName() + newline);
  45.                         }
  46.                 }
  47.                 textArea.append("__________" + newline + newline);
  48.         }
  49. }
  50.  

回复 "applet程序之间的通信"

这儿你可以回复上面这条便签

captcha