第三节课后作业
发布于: 2020 年 10 月 08 日
标题
请在草稿纸上手写一个单例模式的实现代码,拍照提交作业。
请用组合设计模式编写程序,打印输出图 1 的窗口,窗口组件的树结构如图 2 所示,打印输出
解答
1:单例如下
2:
@Datapublic abstract class Windows { String name; List<Windows> components; public void add(Windows compenent){ if(null == components){ components = new ArrayList<>(); } components.add(compenent); } public void setup(){ return ; } public void viewComponents(){ if(null != components){ components.forEach(x->{ System.out.println(x.getName()); if(null != x.getComponents()){ x.getComponents().forEach(y->{ System.out.println(y.getName()); }); } }); } }}@Datapublic class Button extends Windows { public Button(String name){ this.name = name; }}@Datapublic class CheckBox extends Windows{ public CheckBox (String name){ this.name = name; }}@Datapublic class Form extends Windows{ public Form(String name){ this.name = name; this.setup(); } @Override public void setup(){ this.add(new Picture( "LOGO图片")); this.add(new Button("登录")); this.add(new Button("注册")); this.add(new Frame("frame1")); }}@Datapublic class Frame extends Windows { public Frame(String name){ this.name = name; this.setup(); this.name = name; } @Override public void setup(){ this.add(new Label( "用户名")); this.add(new TextBox("文本框")); this.add(new Label("密码")); this.add(new PasswordBox("密码框")); this.add(new CheckBox("复选框")); this.add(new TextBox("记住用户名")); this.add(new LinkLable("忘记密码")); }}@Datapublic class Label extends Windows{ public Label (String name){ this.name = name; }}@Datapublic class LinkLable extends Windows{ public LinkLable (String name){ this.name = name; }}@Datapublic class PasswordBox extends Windows{ public PasswordBox (String name){ this.name = name; }}@Datapublic class Picture extends Windows { private String url; public Picture (String name){ this.name = name; }}@Datapublic class TextBox extends Windows{ public TextBox (String name){ this.name = name; }}
划线
评论
复制
发布于: 2020 年 10 月 08 日 阅读数: 16
happy
关注
还未添加个人签名 2019.09.14 加入
还未添加个人简介
评论