JavaScript 与applet信息交互

本文介绍了一个Java Applet示例,展示了如何通过JavaScript调用Applet中的方法,并介绍了Applet的基本构造、初始化及参数获取等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    
  applet文件:Applet1.java  
  //public   String   getAppletInfo()是javascript中将要调用的方法,编译的时候记得带包    
   
  package   manager_test;  
   
  import   java.awt.*;  
  import   java.awt.event.*;  
  import   java.applet.*;  
  import   javax.swing.*;  
   
  public   class   Applet1   extends   JApplet   {  
      boolean   isStandalone   =   false;  
      String   var0;  
      /**Get   a   parameter   value*/  
      public   String   getParameter(String   key,   String   def)   {  
          return   isStandalone   ?   System.getProperty(key,   def)   :  
              (getParameter(key)   !=   null   ?   getParameter(key)   :   def);  
      }  
   
      /**Construct   the   applet*/  
      public   Applet1()   {  
      }  
      /**Initialize   the   applet*/  
      public   void   init()   {  
          try   {  
              var0   =   this.getParameter("param0",   "");  
          }  
          catch(Exception   e)   {  
              e.printStackTrace();  
          }  
          try   {  
              jbInit();  
          }  
          catch(Exception   e)   {  
              e.printStackTrace();  
          }  
      }  
      /**Component   initialization*/  
      private   void   jbInit()   throws   Exception   {  
          this.setSize(new   Dimension(400,300));  
      }  
      /**Get   Applet   information*/  
      public   String   getAppletInfo()   {  
      System.out.println   ("Applet1");  
          return   "Applet   Information";  
      }  
      /**Get   parameter   info*/  
      public   String[][]   getParameterInfo()   {  
          String[][]   pinfo   =  
              {  
              {"param0",   "String",   ""},  
              };  
          return   pinfo;  
      }  
   
      //static   initializer   for   setting   look   &   feel  
      static   {  
          try   {  
              //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());  
              //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());  
          }  
          catch(Exception   e)   {  
          }  
      }  
  }  
   
  jsp文件Applet1.jsp  
   
  <html>  
  <head>  
  <title>Untitled   Document</title>  
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312">  
  </head>  
   
  <SCRIPT   language=JavaScript>  
  function   PutOut()  
  {  
  window.document.MyApplet.getAppletInfo();  
  }  
  </SCRIPT>  
   
  <body   bgcolor="#FFFFFF">  
  <table   width="90%"   border="0"   cellspacing="5"   cellpadding="5">  
      <tr>  
          <td   colspan="4">  
  <object   id="MyApplet"   classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"   width="580"   height="420"   name="applet"    
          codebase="/plug-in/j2re-1_3_1_01-win-i.exe#Version=1,3,1,1">  
          <param   name="code"       value="manager_test.Applet1.class">  
  <param   name="type"       value="application/x-java-applet;version=1.3">  
  <!--<param   name='archive'       value='SystemStateapplet.jar'>-->  
          </object></td>  
      </tr>  
  </table>  
  <p>&nbsp;</p>  
  <p>  
      <input   type="submit"   name="Submit"   value="Submit"   onClick=PutOut()>  
  </p>  
  </body>  
  </html>  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值