week3
发布于: 2020 年 06 月 22 日
exercise 1 手写一个单例实现
java的
类型是A
构造函数private
创建静态对象
提供获取该对象的public静态方法 getInstance
exercise 2
import java.util.ArrayList;import java.util.List;public class Drive { public static void main(String[] args) { Window window = new Window(); Picture picture = new Picture(); Button login = new Button("登录"); Button register = new Button("注册"); Frame frame = new Frame(); Label userName = new Label("用户名"); TextBox textBox = new TextBox("文本框"); Label password = new Label("密码"); PassWordBox passWordBox = new PassWordBox(); CheckBox checkBox = new CheckBox(); TextBox saveUserName = new TextBox("记住用户密码"); LinkLabel linkLabel = new LinkLabel("忘记密码"); window.addComponent(picture); window.addComponent(login); window.addComponent(register); window.addComponent(frame); frame.addComponent(userName); frame.addComponent(textBox); frame.addComponent(password); frame.addComponent(passWordBox); frame.addComponent(checkBox); frame.addComponent(saveUserName); frame.addComponent(linkLabel); window.print(); }}interface Component { void print();}abstract class Container implements Component { private final List<Component> list = new ArrayList<>(); private final String name; public void addComponent(Component component) { list.add(component); } public Container(String name) { this.name = name; } @Override public void print() { System.out.println(name); for (Component component : list) { component.print(); } }}class Window extends Container { public Window() { super("WINDOW窗口"); }}class Picture implements Component { @Override public void print() { System.out.println("LOGO图片"); }}class Button implements Component { private final String name; public Button(String name) { this.name = name; } @Override public void print() { System.out.println(name); }}class Frame extends Container { public Frame() { super("FRAME1"); }}class Label implements Component { private final String name; public Label(String name) { this.name = name; } @Override public void print() { System.out.println(name); }}class TextBox implements Component { private final String name; public TextBox(String name) { this.name = name; } @Override public void print() { System.out.println(name); }}class PassWordBox implements Component { @Override public void print() { System.out.println("密码框"); }}class CheckBox implements Component { @Override public void print() { System.out.println("复选框"); }}class LinkLabel extends Label { public LinkLabel(String name) { super(name); }}
划线
评论
复制
发布于: 2020 年 06 月 22 日 阅读数: 30
Geek_2e7dd7
关注
还未添加个人签名 2018.11.08 加入
还未添加个人简介
评论