Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Runner1 {
- public static void main(String argv[]) {
- Tag t = new Tag("HTML");
- Tag b = new Tag("BODY");
- t.add(b);
- Tag h = new Tag("H1");
- b.add(h);
- Tag p = new Tag("p");
- b.add(p);
- TextTag a1= new TextTag("alamakota");
- TextTag a2 = new TextTag("hello");
- h.add(a2);
- p.add(a1);
- t.prettyPrint();
- }
- }
- public class Tag {
- public static final String TAB = " ";
- private Tag [] children = new Tag[5];
- private int countChildren = 0;
- protected String name;
- public Tag(String name) {
- this.name=name;
- }
- protected String wciecie(int glebokosc) {
- String wciecie="";
- for (int i = 0; i < glebokosc; i++)
- wciecie+=TAB;
- return wciecie;
- }
- public void add(Tag t) {
- children[countChildren++]=t;
- }
- public void prettyPrint() {
- this.prettyPrint(0);
- }
- public void prettyPrint(int glebokosc) {
- String wciecie = this.wciecie(glebokosc);
- System.out.println(wciecie+"<"+name+">");
- for (int i =0 ; i < countChildren; i++)
- children[i].prettyPrint(glebokosc+1);
- System.out.println(wciecie+"</"+name+">");
- }
- }
- public class TextTag extends Tag {
- public TextTag(String name) {
- super(name);
- }
- public void prettyPrint() {
- this.prettyPrint(0);
- }
- public void prettyPrint(int glebokosc) {
- String wciecie = this.wciecie(glebokosc);
- System.out.println(wciecie+name);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement