public class Composite {
public static void main(String[] args) {
Tables windows1 = new Tables("WinForm(WINDOW 窗口)");
Tables frmaes = new Tables("Frame(FRAME1)");
Data logo = new Data("Picture(LOGO 图片)");
Data login = new Data("Button(登录)");
Data logon = new Data("Button(注册)");
windows1.addNode(logo);
windows1.addNode(login);
windows1.addNode(logon);
windows1.addNode(frmaes);
Data username = new Data("Label(用户名)");
Data textBox = new Data("TextBox(文本框)");
Data passwd = new Data("Label(密码)");
Data passwdBox = new Data("PasswordBox(密码框)");
Data checkBox = new Data("CheckBox(复选框)");
Data rememberUsername = new Data("TextBox(记住用户名)");
Data forgetPasswd = new Data("LinkLabel(忘记密码)");
frmaes.addNode(username);
frmaes.addNode(textBox);
frmaes.addNode(passwd);
frmaes.addNode(passwdBox);
frmaes.addNode(checkBox);
frmaes.addNode(rememberUsername);
frmaes.addNode(forgetPasswd);
windows1.print();
}
}
interface DrawNode{
public void print();
}
class Tables implements DrawNode{
private String info;
private List<DrawNode> nodes = new ArrayList<>();
public Tables(String info) {
this.info = info;
}
protected void addNode(DrawNode node){
nodes.add(node);
}
@Override
public void print() {
System.out.println("print "+info);
nodes.forEach(data -> data.print());
}
}
class Data implements DrawNode{
private String info;
public Data(String info) {
this.info = info;
}
@Override
public void print() {
System.out.println("print "+info);
}
}
评论