架构师 -Week3- 作业
发布于: 2020 年 06 月 24 日
作业一
作业二
package com.yx.jktrain.week3;import java.util.ArrayList;import java.util.List;/** * @author yanx * @date 2020-06-24 6:22 */interface INodeManage { void addNode(INodeManage node); void removeNode(INodeManage node); void print();}//WinFormpublic class WinForm implements INodeManage { private String nodeName; public WinForm(String nodeName) { this.nodeName = nodeName; } List<INodeManage> nodeList = new ArrayList<INodeManage>(); @Override public void addNode(INodeManage node) { nodeList.add(node); } @Override public void removeNode(INodeManage node) { nodeList.remove(node); } @Override public void print() { System.out.println("print WinForm(" + nodeName + ")"); for (INodeManage node : nodeList) { node.print(); } } public static void main(String[] args) { //create nodes WinForm winForm = new WinForm("WINDOW窗口"); winForm.addNode(new Picture("LOGO图片")); winForm.addNode(new Button("登录")); winForm.addNode(new Button("注册")); Frame frame = new Frame("FRAME1"); frame.addNode(new Lable("用户名")); frame.addNode(new TextBox("文本框")); frame.addNode(new Lable("密码")); frame.addNode(new PasswordBox("密码框")); frame.addNode(new CheckBox("复选框")); frame.addNode(new TextBox("记住用户名")); frame.addNode(new LinkLable("忘记密码")); winForm.addNode(frame); //print winForm.print(); }}//Pictureclass Picture implements INodeManage { private String nodeName; public Picture(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print Picture(" + nodeName + ")"); }}//Buttonclass Button implements INodeManage { private String nodeName; public Button(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print Button(" + nodeName + ")"); }}//Frameclass Frame implements INodeManage { private String nodeName; List<INodeManage> nodeList = new ArrayList<INodeManage>(); public Frame(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { nodeList.add(node); } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print Frame(" + nodeName + ")"); for (INodeManage node : nodeList) { node.print(); } }}//Lableclass Lable implements INodeManage { private String nodeName; public Lable(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print Lable(" + nodeName + ")"); }}//TextBoxclass TextBox implements INodeManage { private String nodeName; public TextBox(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print TextBox(" + nodeName + ")"); }}//PasswordBoxclass PasswordBox implements INodeManage { private String nodeName; public PasswordBox(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print PasswordBox(" + nodeName + ")"); }}//CheckBoxclass CheckBox implements INodeManage { private String nodeName; public CheckBox(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print CheckBox(" + nodeName + ")"); }}//LinkLableclass LinkLable implements INodeManage { private String nodeName; public LinkLable(String nodeName) { this.nodeName = nodeName; } @Override public void addNode(INodeManage node) { } @Override public void removeNode(INodeManage node) { } @Override public void print() { System.out.println("print LinkLable(" + nodeName + ")"); }}
输出:
print WinForm(WINDOW窗口)
print Picture(LOGO图片)
print Button(登录)
print Button(注册)
print Frame(FRAME1)
print Lable(用户名)
print TextBox(文本框)
print Lable(密码)
print PasswordBox(密码框)
print CheckBox(复选框)
print TextBox(记住用户名)
print LinkLable(忘记密码)
划线
评论
复制
发布于: 2020 年 06 月 24 日阅读数: 50
龙7
关注
还未添加个人签名 2019.02.12 加入
还未添加个人简介
评论