FileDocCategorySizeDatePackage
Imagemap.javaAPI DocExample4235Thu Aug 08 12:26:32 BST 1996None

Imagemap

public class Imagemap extends Applet

Fields Summary
protected Image
image
protected Vector
rects
private ImagemapRectangle
lastrect
Constructors Summary
Methods Summary
public voiddestroy()

 image.flush(); 
private ImagemapRectanglefindrect(int x, int y)

        int i;
        ImagemapRectangle r = null;
        for(i = 0; i < rects.size(); i++)  {
            r = (ImagemapRectangle) rects.elementAt(i);
            if (r.inside(x, y)) break;
        }
        if (i < rects.size()) return r;
        else return null;
    
protected ImagemapRectanglegetRectangleParameter(java.lang.String name)

        int x, y, w, h;
        URL url;
        String value = this.getParameter(name);
        if (value == null) return null;
        
        try {
            StringTokenizer st = new StringTokenizer(value, ",");
            x = Integer.parseInt(st.nextToken());
            y = Integer.parseInt(st.nextToken());
            w = Integer.parseInt(st.nextToken());
            h = Integer.parseInt(st.nextToken());
            url = new URL(this.getDocumentBase(), st.nextToken());
        } 
        catch (NoSuchElementException e) { return null; }
        catch (NumberFormatException e) { return null; }
        catch (MalformedURLException e) { return null; }
        
        return new ImagemapRectangle(x, y, w, h, url);
    
public voidinit()

        // load the image to be displayed.
        image = this.getImage(this.getDocumentBase(), 
                      this.getParameter("image"));
        // lookup a list of rectangular areas and the URLs they map to.
        rects = new Vector();
        ImagemapRectangle r;
        int i = 0;
        while((r = getRectangleParameter("rect" + i)) != null) {
            rects.addElement(r);
            i++;
        }
    
public booleanmouseDown(java.awt.Event e, int x, int y)

        ImagemapRectangle r = findrect(x, y);
        if (r == null) return false;
        Graphics g = this.getGraphics();
        g.setXORMode(Color.red);
        g.drawRect(r.x, r.y, r.width, r.height);
        lastrect = r;
        this.showStatus("To: " + r.url);
        return true;
    
public booleanmouseUp(java.awt.Event e, int x, int y)

        if (lastrect != null) {
            Graphics g = this.getGraphics();
            g.setXORMode(Color.red);
            g.drawRect(lastrect.x, lastrect.y, lastrect.width, lastrect.height);
            this.showStatus("");
            ImagemapRectangle r = findrect(x,y);
            if ((r != null) && (r == lastrect))
                this.getAppletContext().showDocument(r.url);
            lastrect = null;
        }
        return true;
    
public voidpaint(java.awt.Graphics g)

        g.drawImage(image, 0, 0, this);
    
public voidupdate(java.awt.Graphics g)

 paint(g);