home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / timeslaving / src / scrollingtext.java < prev    next >
Encoding:
Java Source  |  2000-06-23  |  1.9 KB  |  69 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import quicktime.app.image.*;
  10.  
  11. class ScrollingText implements Paintable {
  12.     Font font = new Font ("Helvetica", Font.PLAIN, 30);
  13.     Color col = Color.red;
  14.     int y = 22;
  15.     int oldy = 22;
  16.     int width, height;
  17.     Rectangle[] r = new Rectangle[2];
  18.     boolean doFirstDraw = true;
  19.     
  20.     public void newSizeNotified (QTImageDrawer drawer, Dimension d) {
  21.         width = d.width;
  22.         height = d.height;
  23.         doFirstDraw = true;
  24.     }
  25.     
  26.     /**
  27.      * Paint on the graphics. The supplied component is the component from which
  28.      * the graphics object was derived or related to and is also the component
  29.      * that is the object that paint was called upon that has called this method.
  30.      * The Graphics object is what you should paint on.
  31.      * This maybe an on or off screen graphics.
  32.      * You should not cache this graphics object as it can be different
  33.      * between different calls.
  34.      * @param comp the component from which the Graphics object was derived or 
  35.      * related too.
  36.      * @param g the graphics to paint on.
  37.      */
  38.     public Rectangle[] paint (Graphics g) {
  39.         boolean retFull = false;
  40.         if (doFirstDraw) {
  41.             g.setColor (col);
  42.             g.drawRect (0, 0, width - 1, height - 1);
  43.             g.drawRect (1, 1, width - 3, height - 3);
  44.             retFull = true;
  45.             doFirstDraw = false;
  46.         }
  47.         
  48.         g.clearRect (10, oldy - 20, width - 19, 36);
  49.         g.setFont (font);
  50.         g.setColor (col);
  51.         g.drawString ("Scrolling Java Text", 13, y + 6);
  52.         g.setColor (Color.blue);
  53.         g.drawRect (10, y - 20, width - 20, 35);
  54.         
  55.         //redraw full image
  56.         if (retFull) r[0] = new Rectangle(width, height);
  57.         else {
  58.             r[0] = new Rectangle (10, oldy - 20, width - 19, 37);
  59.  
  60.     // tell QTImageDrawer where we drew
  61.             if (r[1] != null) r[1] = null;
  62.             if (y - oldy != 1)
  63.                 r[1] = new Rectangle (10, y - 20, width - 19, 36);
  64.         }
  65.         
  66.         return r;
  67.     }
  68. }
  69.