写点什么

第三周作业

用户头像
大雄
关注
发布于: 2020 年 06 月 23 日



1. 请在草稿纸上手写一个单例模式的实现代码,拍照提交作业。



2. 请用组合设计模式编写程序,打印输出图 1 的窗口,窗口组件的树结构如图 2 所示,打印输出示例参考图 3。





public interface Component
void print()
}
public class MetaComponent implements Component{
private String name;
MetaComponent(String name){
this.name = name;
}
@Override
public void print() {
System.out.println(name);
}
}
public abstract class Container implements Component{
private List<Component> components = new ArrayList<>();
private String name;
Container(String name){
this.name = name;
}
public void addComponent(Component component){
components.add(component);
}
public void print(){
System.out.println(name);
for(Component c : components){
c.print();
}
}
}
public class WinForm extends Container {
WinForm(String name) {
super(name);
}
}
public class Frame extends Container {
Frame(String name) {
super(name);
}
}
public class Button extends MetaComponent {
Button(String name) {
super(name);
}
}
public class CheckBox extends MetaComponent {
CheckBox(String name) {
super(name);
}
}
public class Label extends MetaComponent {
Label(String name) {
super(name);
}
}
public class LinkLabel extends MetaComponent {
LinkLabel(String name) {
super(name);
}
}
public class PasswordBox extends MetaComponent {
PasswordBox(String name) {
super(name);
}
}
public class Picture extends MetaComponent {
Picture(String name) {
super(name);
}
}
public class TextBox extends MetaComponent {
TextBox(String name) {
super(name);
}
}
public class Main {
public static void main(String[] args) {
WinForm winForm = new WinForm("WinForm(Window窗口)");
Picture picture = new Picture("Picture(LOGO图片)");
Button button1 = new Button("Button(登录)");
Button button2 = new Button("Button(注册)");
Frame frame = new Frame("Frame(FRAME1)");
winForm.addComponent(picture);
winForm.addComponent(button1);
winForm.addComponent(button2);
winForm.addComponent(frame);
Label label = new Label("Label(用户名)");
TextBox textBox = new TextBox(("TextBox(文本框)"));
Label label1 = new Label("Label(密码)");
PasswordBox passwordBox = new PasswordBox("PasswordBox(密码框)");
CheckBox checkBox = new CheckBox("(CheckBox(复选框)");
TextBox textBox1 = new TextBox("TextBox(记住用户名)");
LinkLabel linkLabel = new LinkLabel("LinkLable(忘记密码)");
frame.addComponent(label);
frame.addComponent(textBox);
frame.addComponent(label1);
frame.addComponent(passwordBox);
frame.addComponent(checkBox);
frame.addComponent(textBox1);
frame.addComponent(linkLabel);
winForm.print();
}
}





用户头像

大雄

关注

还未添加个人签名 2018.09.21 加入

还未添加个人简介

评论

发布
暂无评论
第三周作业