home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Documents / JAVA Programming / examples / 18 / ObservedImageLoad.java < prev    next >
Encoding:
Java Source  |  2000-09-08  |  1.2 KB  |  54 lines

  1. /* <title>ObservedImageLoad</title>
  2. * <applet code="ObservedImageLoad" width=290 height=140>
  3. * <param name="img" value="mupk.gif">
  4. * </applet>
  5. */
  6. import java.applet.*;
  7. import java.awt.*;
  8. import java.awt.image.*;
  9. public class ObservedImageLoad extends Applet
  10.                                implements Runnable, ImageObserver {
  11. Image art;
  12. Dimension d;
  13. int progress;
  14. Thread motor;
  15. boolean loaded;
  16. public void init() {
  17. art = getImage(getDocumentBase(), getParameter("img"));
  18. loaded = false;
  19. progress = 0;
  20. }
  21. public void paint(Graphics g)    {
  22. d = this.getSize();
  23. loaded = g.drawImage(art, 0, 0, this);
  24. }
  25. public boolean imageUpdate(Image img, int    info, 
  26.                            int x, int y, int width, int height) {
  27. if((info & ALLBITS) != 1) { 
  28.     if(progress<d.height) {
  29.        progress = progress + height;
  30.     }
  31. System.out.println(progress + "/" + d.height);
  32. return true;
  33. else {
  34. return false;
  35. } }
  36. public void start() {
  37. motor = new Thread(this);
  38. motor. start();
  39. }
  40. public void stop() {
  41. motor.stop();
  42. }
  43. public void run() {
  44. motor.setPriority(Thread.MIN_PRIORITY);
  45. while(!loaded) { // update progress indicator (5 fps) 
  46. repaint();
  47. try {
  48. motor.sleep(200);
  49. }
  50. catch(InterruptedException e) { }
  51. }
  52. } }
  53.