日期:2014-05-20 浏览次数:20861 次
package common;
public abstract class Tag {
    protected int id;
    protected int width;
    protected int height;
    public int getWidth() {
    return width;
    }
    public void setWidth(int width) {
    this.width = width;
    }
    public int getHeight() {
    return height;
    }
    public void setHeight(int height) {
    this.height = height;
    }
    public void setId(int id) {
    this.id = id;
    }
    public abstract void render();
    public int getId() {
    return id;
    }
}
package common;
public class Td extends Tag {
    private String content;
    public Td() {
    super();
    }
    public String getContent() {
    return content;
    }
    public void setContent(String content) {
    this.content = content;
    }
    @Override
    public void render() {
    StringBuffer sb = new StringBuffer("");
    sb.append("<td ");
    if (this.getId() != 0)
        sb.append(" id='" + this.getId() + "'");
    if (this.getWidth() != 0)
        sb.append(" width='" + this.getWidth() + "'");
    if (this.getHeight() != 0)
        sb.append(" height='" + this.getHeight() + "'");
    sb.append(">");
    if (this.getContent() != null)
        sb.append(this.getContent());
    sb.append("</td>");
    System.out.println(sb.toString());
    }
    public static void main(String args[]) {
    Td td = new Td();
    td.setWidth(22);
    td.setHeight(33);
    td.setContent("sdass");
    td.render();
    }
}