1.txt
资源名称:1.rar [点击查看]
上传用户:bfc2008
上传日期:2021-10-06
资源大小:1k
文件大小:1k
源码类别:

Applet

开发平台:

Java

  1. import java.applet.*;
  2. import java.awt.*;
  3. public class LifeCycle extends Applet{
  4. private int InitCnt;
  5. private int StartCnt;
  6. private int StopCnt;
  7. private int DestroyCnt;
  8. private int PaintCnt;
  9. public LifeCycle(){//在init()执行前执行构造函数
  10. InitCnt = 0;
  11. StartCnt = 0;
  12. StopCnt = 0;
  13. DestroyCnt = 0;
  14. PaintCnt = 0;
  15. }
  16. public void init(){
  17. resize(320, 240);
  18. InitCnt++;
  19. }
  20. public void destroy(){
  21. DestroyCnt++;
  22. }
  23. public void start(){
  24. StartCnt++;
  25. }
  26. public void stop(){
  27. StopCnt++;
  28. }
  29. public void paint(Graphics g){
  30. PaintCnt++;
  31. g.drawLine(20,200,300,200); //画出坐标轴和标尺
  32. g.drawLine(20,200,20,20);
  33. g.drawLine(20,170,15,170);
  34. g.drawLine(20,140,15,140);
  35. g.drawLine(20,110,15,110);
  36. g.drawLine(20,80,15,80);
  37. g.drawLine(20,50,15,50);
  38. g.drawString("Init()",25,213);
  39. g.drawString("Start()",75,213);
  40. g.drawString("Stop()",125,213);
  41. g.drawString("Destroy()",175,213);
  42. g.drawString("paint()",235,213);
  43. g.fillRect(25,200-InitCnt*30,40,InitCnt*30); //显示各种方法被调用的次数
  44. g.fillRect(75,200-StartCnt*30,40,StartCnt*30);
  45. g.fillRect(125,200-StopCnt*30,40,StopCnt*30);
  46. g.fillRect(175,200-DestroyCnt*30,40,DestroyCnt*30);
  47. g.fillRect(235,200-PaintCnt*30,40,PaintCnt*30);
  48. }
  49. }