精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>网络专区>>● 网站建设>>Web 编程>>JSP、Servlet>>JAVA/JSP学习系列之十三(JavaScript改变Applet状态)

主题:JAVA/JSP学习系列之十三(JavaScript改变Applet状态)
发信人: 2001asp(ujj)
整理人: eagle(2001-05-19 17:41:42), 站内信件


下面的例子将说明利用javascript去改变applet状态和在javascript中调用applet中的方法。 

一、applet源代码(tmin_JS2.java) 

 // Import
 import java.awt.Graphics ;
 import java.awt.Event ;

 // LiveConnect... for JavaScript
 // Not used... (it's more simple)
 

 public class tmin_JS2 extends java.applet.Applet {
     // Variables
     String str ;       // Sample string...
     int  i ;           // nb change...


     // Initialisation de l'applet
     public void init() {                       // Methode init()
         str = new String("test");
         i = 0 ;
     }

     // Dessiner l'applet
     public void paint(Graphics g) {             // Methode paint()
          g.drawString(str, 5, 10) ;
     }
     
     // setString : change string value 
     public void setString(String s) {    
         str = new String( s );
 i++ ;

        // force repaint to see change
 repaint() ;
return ;
     }

     // getString : get string value 
     public String getString() {    
return str ;
     }

     // getVal : get number of change 
     public int getVal() {    
return i ;
     }
     
  }
 

二、注意的地方

(1)在applet中,要命名:

<APPLET codeBase="./" code=tmin_JS2 width=80 height=25 NAME=test1 >




----
E网情深国立华侨大学商检95本主页(http://sj95.126.com)

          

[关闭][返回]