FileDocCategorySizeDatePackage
ImageMap.javaAPI DocExample1475Thu Apr 03 15:16:28 BST 1997None

ImageMap.java

import java.awt.*;
import java.net.*;
import java.util.*;
import java.applet.*;

public class ImageMap extends Canvas {

  Image theMap;
  Vector areas;
  AppletContext ac;
  
  public ImageMap(Image img, AppletContext browser) {

    theMap = img;
    // make sure the Image is loading
    theMap.getWidth(this);
    ac = browser;
    areas = new Vector();
  }
  
  public void addMapArea(String s) {

    if (s.startsWith("rect")) {
      try {
        RectArea r = new RectArea(s);
        areas.addElement(r);
      }
      catch (MalformedURLException e) {
        System.err.println(e);
      }
    }
    else if (s.startsWith("circle")) {
      ;
    }
    else if (s.startsWith("poly")) {
      ;
    }
    else if (s.startsWith("oval")) {
      ;
    }
    else {  // unrecognized tag
      ;
    }
    
  }

    
  public boolean mouseDown(Event evt, int x, int y) {
    for (Enumeration e = areas.elements() ; e.hasMoreElements() ;) {
      MapArea a = (MapArea) e.nextElement();
      if (a.contains(x, y)) {
        ac.showDocument(a.getURL());
        break;
      }
    }
    return true;
  
  }


  public void paint(Graphics g) {
   
     if(!g.drawImage(theMap, 0, 0, this)) {
       g.drawString("Loading Picture. Please hang on", 25, 50);
     }
     
  }

  public Dimension minimumSize() {
  
    return new Dimension(theMap.getWidth(this), theMap.getHeight(this));
  
  }

  public Dimension preferredSize() {
  
    return minimumSize();
  
  }

  
}