locationbuilder.java
来自「Online Map for Mobile」· Java 代码 · 共 59 行
JAVA
59 行
import java.util.Vector;
public class LocationBuilder extends XMLBuilder {
public XMLBuilder addElement(String name) {
if (name.equals("point")) {
return new XMLBuilder() {
public void addAttribute(String name, String value) {
if (name.equals("x")) {
x = value;
} else if (name.equals("y")) {
y = value;
} else {
throw new XMLException("\"x\" or \"y\" attributes expected");
}
}
public void closeElement() {
points.addElement(x);
points.addElement(y);
}
private String x;
private String y;
};
} else {
throw new XMLException("<point> elements expected");
}
}
public void addAttribute(String name, String value) {
if (name.equals("name")) {
location.name = value;
} else if (name.equals("image")) {
location.image = value;
} else {
throw new XMLException("\"name\" or \"type\" attributes expected");
}
}
public void setValue(String value) {
location.info = value;
}
public void closeElement() throws NumberFormatException {
Vector src = points;
short[] dst = location.points = new short[points.size()];
for (int i = 0, n = dst.length; i < n; i++) {
dst[i] = Short.parseShort((String)src.elementAt(i));
}
}
LocationBuilder(Location location) {
this.location = location;
points = new Vector();
}
Location location;
Vector points;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?