写点什么

第 3 周作业

用户头像
uangguan
关注
发布于: 2020 年 06 月 24 日

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

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

public class App
{
public static void main( String[] args )
{
WinForm winForm = new WinForm("window窗口");
Picture picture = new Picture("Logo图片");
Button button = new Button("登录");
Button button2 = new Button("注册");
Frame frame = new Frame("frame1");
Lable lable = new Lable("用户名");
TextBox textBox = new TextBox("文本框");
Lable lable2 = new Lable("密码");
PasswordBox passwordBox = new PasswordBox("密码框");
CheckBox checkBox = new CheckBox("复选框");
TextBox textBox2 = new TextBox("记住用户名");
LinkLable linkLable = new LinkLable("忘记密码");
winForm.addComponent(picture);
winForm.addComponent(button);
winForm.addComponent(button2);
winForm.addComponent(frame);
frame.addComponent(lable);
frame.addComponent(textBox);
frame.addComponent(lable2);
frame.addComponent(passwordBox);
frame.addComponent(checkBox);
frame.addComponent(textBox2);
frame.addComponent(linkLable);
winForm.drawComponent();
}
}



package org.example;
import java.util.ArrayList;
import java.util.List;
public abstract class Component {
protected String name;
private List<Component> childrens = new ArrayList<>();
public void drawComponent(){
for (Component commponent :
childrens) {
commponent.drawComponent();
}
};
public void addComponent(Component component) {
childrens.add(component);
}
}



package org.example;
public class Button extends Component{
public Button(String name) {
this.name = name;
}
@Override
public void drawComponent() {
System.out.println(name);
}
}



package org.example;
public class CheckBox extends Component{
public CheckBox(String name) {
this.name = name;
}
@Override
public void drawComponent() {
System.out.println(name);
}
}



package org.example;
public class Frame extends Component{
public Frame(String name) {
this.name = name;
}
}



package org.example;

public class Lable extends Component{

public Lable(String name) {
this.name = name;
}

@Override
public void drawComponent() {
System.out.println(name);
}
}




package org.example;

public class LinkLable extends Component{

public LinkLable(String name) {
this.name = name;
}

@Override
public void drawComponent() {
System.out.println(name);
}
}




package org.example;

public class PasswordBox extends Component{

public PasswordBox(String name) {
this.name = name;
}

@Override
public void drawComponent() {
System.out.println(name);
}
}




package org.example;

public class Picture extends Component{

public Picture(String name) {
this.name = name;
}

@Override
public void drawComponent() {
System.out.println(name);
}
}




package org.example;

public class TextBox extends Component{

public TextBox(String name) {
this.name = name;
}

@Override
public void drawComponent() {
System.out.println(name);
}
}




package org.example;

public class WinForm extends Component{

public WinForm(String name) {
this.name = name;
}

}




用户头像

uangguan

关注

还未添加个人签名 2017.10.20 加入

还未添加个人简介

评论

发布
暂无评论
第3周作业