Java Applet运行机制分析



Applet运行之前,先调用Init()方法,然后调用start()方法,最后调用paint()方法。

stop()方法主要发生在Applet所在的网页被最小化时,当Applet所在的网页被最大化时,要调用start()方法和paint()方法。

paint()方法主要发生Applet所在网页由非活动状态变为活动状态时,如从另一个窗口转到Applet所在的网页的窗口时,将调用paint方法。再者,其它方法调用repaint()方法,也将间接调用paint()方法。

下面的代码是测试Applet的代码:

AppletDemo.java文件:

import java.awt.*;

public class AppletDemo extends java.applet.Applet {
   
      /** Initialization method that will be called after the applet is loaded
       *    into the browser.
       */
      public void init() {
          // TODO start asynchronous download of heavy resources
          System.out.println("Init start");
      }
public void start(){
    System.out.println("Start start");
}
public void stop(){
    System.out.println("Stop start");
}
public void destory(){
    System.out.println("Destory start");
}
      public void paint(Graphics g) {
          System.out.println("Paint start");
      }
}

AppletDemo.html文件:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
</head>
<body bgcolor="000000">
    <center>
     <applet
      code = "AppletDemo.class"
      width = "500"
      height = "300"
      >
     </applet>
    </center>
</body>
</html>

你可能感兴趣的:(java,html,活动)