home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Japan / NTT / DM- / hotjava / classes / src / AnimationPlayer.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  2.3 KB  |  135 lines

  1. import browser.*;
  2. import browser.audio.*;
  3. import awt.*;
  4. import net.www.html.*;
  5. import java.io.*;
  6. import net.www.*;
  7. import java.util.*;
  8.  
  9. // Animation Data Type
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. // AnimationData ID
  18.  
  19.  
  20. // Animation Depth for no image (i.e. sound only data)
  21.  
  22.  
  23. class AnimationPlayer extends Applet implements Runnable {
  24.  
  25. // test for MouseMove event
  26. int last_x = -1;
  27. int last_y = -1;
  28.  
  29. static String imgdir = "images";
  30. static String snddir = "audio";
  31.  
  32. boolean    initialized = false;
  33.  
  34. // various image file names
  35.  
  36. // offscreen image & graphic context
  37. Image        im = null;
  38. Graphics    offscreen;
  39. int        width, height;
  40.  
  41. // Various Images
  42. Image        background = null;
  43.  
  44. IDChain        dispobj = null;
  45.  
  46. AnimationData    adList[] = null;
  47. int        maxAnimation = 0;
  48. Schedular    sched[] = null;
  49. int        maxSchedular = 0;
  50.  
  51. public AnimationData getAnimationData(int n) {return adList[n];}
  52.  
  53. void setupDisplayObject() {
  54.     int i;
  55.     for (i = 0; i < maxAnimation; i++) {
  56.     if (adList[i] != null && adList[i].getDepth() >= 0) {
  57.         dispobj.insertByDepth(new IDChain(i, 0, adList[i].getDepth()));
  58.     }
  59.     }
  60. }
  61.  
  62. public void start() {
  63.     startDisplay();
  64.     repaint();
  65. }
  66.  
  67. private void startDisplay() {
  68.     int i;
  69.     AnimationData ad;
  70.  
  71.     sched[0] = new Schedular(this, 0);
  72.     for (i = 0; i < maxAnimation; i++) {
  73.     if ((ad=adList[i]) == null) {
  74.         continue;
  75.     }
  76.     if (ad.getType() == 1) {
  77.         sched[0].reschedule(i);
  78.     } else if (ad.getCurFrame() == -1) {
  79.         ad.setCurFrame(0);
  80.     }
  81.     }
  82.     sched[0].start();
  83. }
  84.  
  85.  
  86. public void run() {
  87. }
  88.  
  89. public void stop() {
  90.     int i;
  91.     for (i=0; i < maxSchedular; i++) {
  92.     if (sched[i] != null) {
  93.         sched[i].stop();
  94.         sched[i] = null;
  95.     }
  96.     }
  97. }
  98.  
  99. public void paint(Graphics g) {
  100.     update(g);
  101. }
  102.  
  103. public void update(Graphics g) {
  104.     offscreen.setForeground(Color.lightGray);
  105.     offscreen.fillRect(0,0,width,height);
  106.     offscreen.drawImage(background, 0, 0);
  107.  
  108.     IDChain p;
  109.     AnimationData ad;
  110.     Image img;
  111.     for (p = dispobj.getNext(); p != null; p = p.getNext()) {
  112.     ad = adList[p.getID()];
  113.     if ((img=ad.getCurrentImage()) != null) {
  114.         offscreen.drawImage(img, ad.x(), ad.y());
  115.     }    
  116.     }
  117.     g.drawImage(im,0,0);
  118. }
  119.  
  120. public void insertSchedular(int id) {
  121.     sched[id] = new Schedular(this, id);
  122.     sched[id].reschedule(id);
  123.     sched[id].start();
  124. }
  125.  
  126. public void removeSchedular(int id) {
  127.     if (sched[id] != null) {
  128.     sched[id].stop();
  129.     sched[id] = null;
  130.     }
  131. }
  132.  
  133. }
  134.  
  135.