写点什么

【架构思维学习】 week03

用户头像
chun1123
关注
发布于: 2020 年 06 月 25 日

作业一 手写单例模式


作业二 设计窗口组件

类图


父类,WinItem


public class WinItem {    protected String name;    //    private String type;    protected String text;
public WinItem(String name, String text) { this.name = name;// this.type = type; this.text = text; }
public void draw() { System.out.println(text); }
}
复制代码

WinContainer 子类


public class WinContainer extends WinItem {    protected List<WinItem> children = new ArrayList<>();    public WinContainer(String name, String text) {        super(name, text);    }    public void addChildren(WinItem item){        children.add(item);    }
public void removeChildren(WinItem item){ children.remove(item); }
@Override public void draw(){ System.out.println(text); children.forEach(item -> item.draw()); }}
复制代码

IFrame 继承 WinContainer

public class IFrame extends WinContainer {    public IFrame(String name,String text) {        super(name, text);    }}
复制代码

Button,CheckBox,IFrame,Img,InputBox,Label,LinkLabel,PasswordBox,均继承 WinItem


public class Button extends WinItem {    public Button(String name, String text) {        super(name, text);    }}...
复制代码


测试代码

public class WinTest {    public static void main(String[] args) {        WinContainer winContainer = new WinContainer("index", "WINDOW窗口");        Img img = new Img("LOGO","LOGO图片");        Button loginButton = new Button("login", "登录");        Button registerButton = new Button("register", "注册");        winContainer.addChildren(img);        winContainer.addChildren(loginButton);        winContainer.addChildren(registerButton);
IFrame iFrame = new IFrame("FRAME1", "FRAME1"); Label usernameLabel = new Label("usernameLabel", "文本框"); Label passwordLabel = new Label("passwordLabel", "密码"); InputBox usernameBox = new InputBox("usernameLabel", "用户名"); PasswordBox passwordBox = new PasswordBox("passwordLabel", "密码框"); CheckBox checkBox = new CheckBox("checkbox", "复选框"); Label checkLabel = new Label("checkLabel", "记住用户名"); LinkLabel forgetPassword = new LinkLabel("forgetPasswordLink", "忘记密码"); iFrame.addChildren(usernameLabel); iFrame.addChildren(usernameBox); iFrame.addChildren(passwordLabel); iFrame.addChildren(passwordBox); iFrame.addChildren(checkBox); iFrame.addChildren(checkLabel); iFrame.addChildren(forgetPassword);
winContainer.addChildren(iFrame);
winContainer.draw();
}}
复制代码


输出

public class WinTest {    public static void main(String[] args) {        WinContainer winContainer = new WinContainer("index", "WINDOW窗口");        Img img = new Img("LOGO","LOGO图片");        Button loginButton = new Button("login", "登录");        Button registerButton = new Button("register", "注册");        winContainer.addChildren(img);        winContainer.addChildren(loginButton);        winContainer.addChildren(registerButton);
IFrame iFrame = new IFrame("FRAME1", "FRAME1"); Label usernameLabel = new Label("usernameLabel", "文本框"); Label passwordLabel = new Label("passwordLabel", "密码"); InputBox usernameBox = new InputBox("usernameLabel", "用户名"); PasswordBox passwordBox = new PasswordBox("passwordLabel", "密码框"); CheckBox checkBox = new CheckBox("checkbox", "复选框"); Label checkLabel = new Label("checkLabel", "记住用户名"); LinkLabel forgetPassword = new LinkLabel("forgetPasswordLink", "忘记密码"); iFrame.addChildren(usernameLabel); iFrame.addChildren(usernameBox); iFrame.addChildren(passwordLabel); iFrame.addChildren(passwordBox); iFrame.addChildren(checkBox); iFrame.addChildren(checkLabel); iFrame.addChildren(forgetPassword);
winContainer.addChildren(iFrame); winContainer.draw(); }}
复制代码


用户头像

chun1123

关注

还未添加个人签名 2018.03.09 加入

还未添加个人简介

评论

发布
暂无评论
【架构思维学习】 week03