import java.awt.Rectangle;
import java.util.StringTokenizer;
import java.net.*;
public class RectArea extends MapArea {
Rectangle r;
// An NCSA format String looks like
// rect http://www.macfaq.com 227,0 340,65
public RectArea (String s) throws MalformedURLException {
int x1, y1, x2, y2;
StringTokenizer st = new StringTokenizer(s, " \n\t\r,");
// throw away the first token
// This should be ³rect²
st.nextToken();
u = new URL(st.nextToken());
x1 = Integer.parseInt(st.nextToken());
y1 = Integer.parseInt(st.nextToken());
x2 = Integer.parseInt(st.nextToken());
y2 = Integer.parseInt(st.nextToken());
r = new Rectangle(x1, y1, x2 - x1, y2 - y1);
}
public boolean contains(int x, int y) {
return r.inside(x, y);
}
public String toString() {
return "rect " + u + " " + r.x + "," + r.y + " "
+ (r.x + r.width) + "," + (r.y + r.height);
}
}
|