home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / AniArea.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  3.3 KB  |  102 lines

  1. // $Header: z:/admin/metro_examples/java/demo/ImageMap/rcs/AniArea.java 1.1 1997/02/06 00:30:13 IPGIntel-2 Exp $ 
  2. /*
  3.  * @(#)AniArea.java    1.8 96/12/06
  4.  *
  5.  * Copyright (c) 1994-1996 Sun Microsystems, Inc. All Rights Reserved.
  6.  *
  7.  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
  8.  * modify and redistribute this software in source and binary code form,
  9.  * provided that i) this copyright notice and license appear on all copies of
  10.  * the software; and ii) Licensee does not utilize the software in a manner
  11.  * which is disparaging to Sun.
  12.  *
  13.  * This software is provided "AS IS," without a warranty of any kind. ALL
  14.  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
  15.  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
  16.  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
  17.  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  18.  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
  19.  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
  20.  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
  21.  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
  22.  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
  23.  * POSSIBILITY OF SUCH DAMAGES.
  24.  *
  25.  * This software is not designed or intended for use in on-line control of
  26.  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
  27.  * the design, construction, operation or maintenance of any nuclear
  28.  * facility. Licensee represents and warrants that it will not use or
  29.  * redistribute the Software for such purposes.
  30.  */
  31.  
  32. import java.awt.Graphics;
  33. import java.util.StringTokenizer;
  34. import java.awt.Image;
  35. import java.net.URL;
  36. import java.net.MalformedURLException;
  37.  
  38. /**
  39.  * This ImageArea provides for a button that animates when the mouse is
  40.  * over it. The animation is specifed as a base image that contains all
  41.  * of the animation frames and then a series of X,Y coordinate pairs that
  42.  * define the top left corner of each new frame.
  43.  *
  44.  * @author    Chuck McManis
  45.  * @version    1.8, 12/06/96
  46.  */
  47. class AniArea extends ImageMapArea {
  48.  
  49.     Image sourceImage;
  50.     int     nFrames;
  51.     int  coords[];
  52.     int     currentFrame = 0;
  53.  
  54.     public void handleArg(String s) {
  55.     StringTokenizer st = new StringTokenizer(s, ", ");
  56.     int    i;
  57.         String imgName;
  58.  
  59.     imgName = st.nextToken();
  60.     try {
  61.         sourceImage = parent.getImage(new URL(parent.getDocumentBase(),
  62.                           imgName));
  63.         parent.addImage(sourceImage);
  64.     } catch (MalformedURLException e) {}
  65.  
  66.     nFrames = 0;
  67.     coords = new int[40];
  68.  
  69.     while (st.hasMoreTokens()) {
  70.         coords[nFrames*2]     = Integer.parseInt(st.nextToken());
  71.         coords[(nFrames*2)+1] = Integer.parseInt(st.nextToken());
  72.         nFrames++;
  73.         if (nFrames > 19)
  74.         break;
  75.     }
  76.     }
  77.  
  78.     public boolean animate() {
  79.     if (entered) {
  80.         repaint();
  81.     }
  82.     return entered;
  83.     }
  84.  
  85.     public void enter() {
  86.     currentFrame = 0;
  87.     parent.startAnimation();
  88.     }
  89.  
  90.     public void highlight(Graphics g) {
  91.     if (entered) {
  92.         drawImage(g, sourceImage, 
  93.               X-coords[currentFrame*2], Y-coords[(currentFrame*2)+1],
  94.               X, Y, W, H);
  95.         currentFrame++;
  96.         if (currentFrame >= nFrames)
  97.         currentFrame = 0;
  98.     }
  99.     }
  100. }
  101.  
  102.