Imagemappublic class Imagemap extends Applet
Fields Summary |
---|
protected Image | image | protected Vector | rects | private ImagemapRectangle | lastrect |
Methods Summary |
---|
public void | destroy() image.flush();
| private ImagemapRectangle | findrect(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 ImagemapRectangle | getRectangleParameter(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 void | init()
// 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 boolean | mouseDown(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 boolean | mouseUp(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 void | paint(java.awt.Graphics g)
g.drawImage(image, 0, 0, this);
| public void | update(java.awt.Graphics g) paint(g);
|
|