⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 right6_3_3.htm

📁 清华大学JAVA教程
💻 HTM
字号:
<html><head><title>JAVA编程语言</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link rel="stylesheet" href="../../../css/text.css" type="text/css"></head><body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" ><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">  <tr>     <td valign="top">       <table width="94%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#FFFFFF">        <tr>          <td valign="top">             <p> <span class="pt9-black">  在Applet类中提供了许多方法,使之可以与浏览器进行通信。下面对这些方法进行简要的介绍:<br>              一个Web页可包含一个以上的小应用程序。一个Web页中的多个小应用程序可以直接通过java.applet包中提供的方法进行通信。</span></p>            <p class="pt9-black">  getDocumentBase( ) <font color="339900">//返回当前网页所在的URL</font><br>                getCodeBase( ) <font color="339900">//返回当前applet所在的URL</font><br>                getImage(URL base,String target) <font color="339900">//返回网址URL中名为target的图像</font><br>                getAudioClip(URL base,String target) <font color="339900"><br>                               //返回网址URL中名为target的声音对象</font><br>                getParameter(String target ) <font color="339900">//提取HTML文件中名为target的参数的值</font></p>            <p class="pt9-black">  同页Applet间的通信<br>                在java.applet.Applet类中提供了如下方法得到当前运行页的环境上下文AppletContext对象。<br>                public AppletContext getAppletContext();<br>              <br>                通过AppletContext对象,可以得到当前小应用程序运行环境的信息。AppletContext是一个接口,其中定义了一些方法可以得到当前页的其它小应用程序,进而实现同页小应用程序之间的通信。<br>              <br>                (1)得到当前运行页的环境上下文AppletContext对象<br>                   public AppletContext getAppletContext();<br>                (2)取得名为name的Applet对象<br>                   public abstract Applet getApplet(String name);<br>                (3)得到当前页中所有Applet对象<br>                   public abstract Enumeration getApplets();</p>            <p class="pt9-black"><img src="../../../images/html/liti.gif" width="38" height="38" align="absbottom" title="例题">               <font color="000099">例6.11</font><br>                 import java.applet.*;<br>                 import java.awt.*;<br>                 import java.awt.event.*;<br>                 import java.util.Enumeration;<br>                 public class GetApplets extends Applet implemements ActionListener               {<br>                   private TextArea textArea; <font color="339900">//声明一个TextArea</font><br>                   private String newline; <br>                   public void init() {<br>                     Button b=new Button(&quot;Click to call getApplets()&quot;);<br>                     b.addActionListener(this);<br>                     setLayout(new BorderLayout());</p>            <p class="pt9-black">      add(&quot;North&quot;,b);<br>                   textArea=new TextAred(5,40);<br>                   textArea.setEditable(false);<br>                   add(&quot;Center&quot;,textArea);<br>                   newline=System.getProperty(&quot;line,separator&quot;); <font color="339900"><br>                             //取得系统当前的换行符</font><br>                 }<br>                   public void actionPerformed(ActionEvent event) { <font color="339900"><br>                            /*Button b点击后的事件处理函数*/</font><br>                     printApplets(); <br>                   }<br>                   public String getAppletInfo() {<br>                     return &quot;GetApplets by Dong.li&quot;;<br>                 }</p>            <p class="pt9-black"><br>                 public void printApplets()}<br>                     Enumeration e=getAppletContext().getApplets(); <font color="339900"><br>                           /*得到当前网页所有的Applet对象*/</font><br>                     textArea.append(&quot;Results of getApplets():&quot; + newline);<br>                     while(e.hasMoreElements()) {<br>                       Applet applet=(Applet) e.nextElement();<br>                       String info=((Applet)applet).getAppletInfo(); <font color="339900"><br>                          /*逐个取得当前网页Applet对象的信息*/</font><br>                       if (info!=null) {<br>                         textArea.append(&quot;-&quot;+info+newline); <font color="339900"><br>                          /*在textArea中输出网页所有Applet的信息*/</font><br>                       } else {<br>                         textArea.append(&quot;-&quot;+applet.getClass().getName()+newline)	              ; <br>                       }<br>                       }<br>                         textArea.append(&quot;__________&quot;+newline+newline);<br>                     }<br>                 }</p>            </td>        </tr>      </table>    </td>  </tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -