写点什么

【架构师训练营】第三周作业

用户头像
Mr.hou
关注
发布于: 2020 年 06 月 23 日



作业1:手写单列



作业2:请用组合设计模式编写程序,打印输出图 1 的窗口,窗口组件的树结构如图 2 所示,打印输出示例参考图 3。





package com.houzh.Composite;
/**
* @Author: houzh
* @Date: 2020/6/23 10:30 上午
*/
public abstract class Component {
protected String name;
public Component(String name) {
this.name = name;
}
public void print(){
System.out.println(String.format("%s(%s)", this.getClass().getSimpleName(), name));
}
}



package com.houzh.Composite;
import com.google.common.collect.Lists;
import java.util.List;
/**
* @Author: houzh
* @Date: 2020/6/23 10:33 上午
*/
public abstract class Container extends Component {
List<Component> list = Lists.newArrayList();
public Container(String name) {
super(name);
}
public void add(Component c){
list.add(c);
}
@Override
public void print() {
super.print();
for (Component c:list){
c.print();
}
}
}



package com.houzh.Composite;
/**
* @Author: houzh
* @Date: 2020/6/23 10:37 上午
*/
public class WindowForm extends Container {
public WindowForm(String name) {
super(name);
}
}



package com.houzh.Composite;
/**
* @Author: houzh
* @Date: 2020/6/23 10:39 上午
*/
public class Picture extends Container {
public Picture(String name) {
super(name);
}
}
public class Button extends Container {
public Button(String name) {
super(name);
}
}
public class CheckBox extends Container {
public CheckBox(String name) {
super(name);
}
}
public class Frame extends Container {
public Frame(String name) {
super(name);
}
}
public class Label extends Container {
public Label(String name) {
super(name);
}
}
public class LinkLabel extends Container {
public LinkLabel(String name) {
super(name);
}
}
public class PasswordBox extends Container {
public PasswordBox(String name) {
super(name);
}
}
public class TextBox extends Container {
public TextBox(String name) {
super(name);
}
}



package com.houzh.Composite;
/**
* @Author: houzh
* @Date: 2020/6/23 10:40 上午
*/
public class Main {
public static void main(String[] args) {
WindowForm windowForm = new WindowForm("Window窗口");
windowForm.add(new Picture("Logo图片"));
windowForm.add(new Button("登录"));
windowForm.add(new Button("注册"));
Frame frame = new Frame("FRAME1");
frame.add(new Label("用户名"));
frame.add(new TextBox("文本"));
frame.add(new Label("密码"));
frame.add(new PasswordBox("密码框"));
frame.add(new CheckBox("复选框"));
frame.add(new TextBox("记住用户名"));
frame.add(new LinkLabel("忘记密码"));
windowForm.add(frame);
windowForm.print();
}
}



WindowForm(Window窗口)
Picture(Logo)
Button(登录)
Button(注册)
Frame(FRAME1)
Label(用户名)
TextBox(文本)
Label(密码)
PasswordBox(密码框)
CheckBox(复选框)
TextBox(记住用户名)
LinkLabel(忘记密码)



用户头像

Mr.hou

关注

还未添加个人签名 2018.09.22 加入

还未添加个人简介

评论

发布
暂无评论
【架构师训练营】第三周作业