第三周作业
发布于: 2020 年 06 月 24 日
说明: 实现打印功能,所有组件均实现接口IDraw接口中的print方法,Frame是父类型组件,可以包含子组件,WinForm是窗体组件,可以包含任意组件,是最高层组件
public class Button implements IDraw{ public Button(String title){ this.title = title; } private String title; @Override public void print() { System.out.println(title+"按钮"); }}
public class CheckBox implements IDraw{ public CheckBox(String title){ this.title = title; } private String title; @Override public void print() { System.out.println("复选框:"+title); }}
public class Frame implements IDraw{ public Frame(String title){ this.title = title; } private String title; private List<IDraw> children = new ArrayList<>(); @Override public void print() { System.out.println("***"+title+"***开始"); for(IDraw child:children){ child.print(); } System.out.println("***"+title+"***结束"); } /** * 添加子组件 * @param iDraw */ public void addChild(IDraw iDraw){ children.add(iDraw); }}
public interface IDraw { //单元 void print();}
public class Label implements IDraw{ public Label(String title){ this.title = title; } private String title; @Override public void print() { System.out.println("标签:"+title); }}
public class LinkLabel implements IDraw{ public LinkLabel(String title){ this.title = title; } private String title; @Override public void print() { System.out.println("跳转链接:"+title); }}
public class PasswordBox implements IDraw{ public PasswordBox(String title){ this.title = title; } private String title; @Override public void print() { System.out.println("密码框:"+title); }}
public class Pictrue implements IDraw{ public Pictrue(String title){ this.title = title; } private String title; @Override public void print() { System.out.println("图片:"+title); }}
public class TextBox implements IDraw{ public TextBox(String title){ this.title = title; } private String title; @Override public void print() { System.out.println("文本框:"+title); }}
public class WinForm implements IDraw{ public WinForm(String title){ this.title = title; } private String title; private List<IDraw> children = new ArrayList<>(); @Override public void print() { System.out.println("==="+title+"===开始"); for(IDraw child:children){ child.print(); } System.out.println("==="+title+"===结束"); } /** * 添加子组件 * @param iDraw */ public void addChild(IDraw iDraw){ children.add(iDraw); }}
划线
评论
复制
发布于: 2020 年 06 月 24 日 阅读数: 25
嘻哈
关注
还未添加个人签名 2018.02.13 加入
还未添加个人简介
评论