home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / MB-JAVA.EXE / ScrollCanvas.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-11-20  |  1.8 KB  |  67 lines

  1. import java.awt.Canvas;
  2. import java.awt.Component;
  3. import java.awt.Dimension;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.MediaTracker;
  7.  
  8. class ScrollCanvas extends Canvas {
  9.    Image sourceImage;
  10.    int widthImage;
  11.    int heightImage;
  12.    int pos;
  13.    Dimension offDimension;
  14.    Image offImage;
  15.    Graphics offGraphics;
  16.    MediaTracker tracker;
  17.  
  18.    public ScrollCanvas(Image var1) {
  19.       this.sourceImage = var1;
  20.       this.tracker = new MediaTracker(this);
  21.       this.tracker.addImage(var1, 0);
  22.       ((Component)this).reshape(0, 0, 500, 100);
  23.    }
  24.  
  25.    protected void finalize() throws Throwable {
  26.       this.tracker = null;
  27.       this.offGraphics = null;
  28.       this.offImage = null;
  29.       super.finalize();
  30.    }
  31.  
  32.    public void scrollImage(int var1) {
  33.       this.pos += var1;
  34.       if (this.pos < -this.widthImage) {
  35.          this.pos += this.widthImage;
  36.       }
  37.  
  38.    }
  39.  
  40.    public void paintScreen(Graphics var1) {
  41.       var1.drawImage(this.sourceImage, this.pos, 0, this);
  42.       var1.drawImage(this.sourceImage, this.pos + this.widthImage, 0, this);
  43.    }
  44.  
  45.    public void update(Graphics var1) {
  46.       if ((this.tracker.statusAll(true) & 8) == 0) {
  47.          var1.drawString("(c)1996 MYSTiC BYTES. HOlD oN...", 10, 50);
  48.       } else {
  49.          this.widthImage = this.sourceImage.getWidth(this);
  50.          this.heightImage = this.sourceImage.getHeight(this);
  51.          ((Component)this).reshape(0, 0, this.widthImage, this.heightImage);
  52.          if (this.offGraphics == null || this.widthImage != this.offDimension.width || this.heightImage != this.offDimension.height) {
  53.             this.offDimension = new Dimension(this.widthImage, this.heightImage);
  54.             this.offImage = ((Component)this).createImage(this.widthImage, this.heightImage);
  55.             this.offGraphics = this.offImage.getGraphics();
  56.          }
  57.  
  58.          this.paintScreen(this.offGraphics);
  59.          var1.drawImage(this.offImage, 0, 0, this);
  60.       }
  61.    }
  62.  
  63.    public void paint(Graphics var1) {
  64.       this.update(var1);
  65.    }
  66. }
  67.