第三周
发布于: 2020 年 10 月 04 日
1.单例模式的实现代码,利用枚举的特性,让JVM来帮我们保证线程安全和单一实例的问题
2.组合设计模式编写程序
public interface WinForm { void add(WinForm winForm); void remove(WinForm winForm); void print();}public class Frame implements WinForm{ private List<WinForm> list = new ArrayList<>(); private String name; public Frame(String name) { this.name = name; } @Override public void add(WinForm winForm) { list.add(winForm); } @Override public void remove(WinForm winForm) { list.remove(winForm); } @Override public void print() { System.out.println(this.name); for (WinForm winForm : list){ winForm.print(); } }}public class Element implements WinForm { private String name; public Element(String name) { this.name = name; } @Override public void add(WinForm winForm) { } @Override public void remove(WinForm winForm) { } @Override public void print() { System.out.println(name); } public static void main(String[] args) { WinForm winForm = new Frame("WinForm(WINDOW窗口)"); winForm.add(new Element("Picture(LOGO图片)")); winForm.add(new Element("Button(登录)")); winForm.add(new Element("Button(注册)")); WinForm frame = new Frame("Frame(FRAME1)"); frame.add(new Element("Lable(用户名)")); frame.add(new Element("TextBox(文本框)")); frame.add(new Element("Lable(密码)")); frame.add(new Element("PasswordBox(密码框)")); frame.add(new Element("CheckBox(复选框)")); frame.add(new Element("TextBox(记住用户名)")); frame.add(new Element("LinkLable(忘记密码)")); winForm.add(frame); winForm.print(); }}
划线
评论
复制
发布于: 2020 年 10 月 04 日 阅读数: 15
等燕归
关注
还未添加个人签名 2019.03.29 加入
还未添加个人简介
评论