架构师训练营第三周作业

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

1、单例代码:



2、结果:

代码:

主函数(WinForm.java)

package Week3;
public class WinForm {
public static void main(String[] args) {
WindowForm windowForm = new WindowForm("Window窗口");
windowForm.add(new Picture("Logo图片"));
windowForm.add(new Button("登录"));
windowForm.add(new Button("注册"));
Frame frame = new Frame("FRAME1");
frame.add(new Label("用户名"));
frame.add(new TextBox("文本"));
frame.add(new Label("密码"));
frame.add(new PasswordBox("密码框"));
frame.add(new CheckBox("复选框"));
frame.add(new TextBox("记住用户名"));
frame.add(new LinkLabel("忘记密码"));
windowForm.add(frame);
windowForm.print();
}
}

WindowForm.java

package Week3;
public class WindowForm extends Container {
public WindowForm(String name) {
super(name);
}
}

Container.java

package Week3;
import java.util.ArrayList;
import java.util.List;
public abstract class Container extends Component {
List<Component> list = new ArrayList<>();
public Container(String name) {
super(name);
}
public void add(Component c){
list.add(c);
}
@Override
public void print() {
super.print();
for (Component c:list){
c.print();
}
}
}

Picture.java

package Week3;
public class Picture extends Container {
public Picture(String name) {
super(name);
}
}

CheckBox.java

package Week3;
public class CheckBox extends Container {
public CheckBox(String name) {
super(name);
}
}

Frame.java

package Week3;
public class Frame extends Container {
public Frame(String name) {
super(name);
}
}

Label.java

package Week3;
public class Label extends Container {
public Label(String name) {
super(name);
}
}

LinkLabel.java

package Week3;
public class LinkLabel extends Container {
public LinkLabel(String name) {
super(name);
}
}

PasswordBox.java

package Week3;
public class PasswordBox extends Container {
public PasswordBox(String name) {
super(name);
}
}

TextBox.java

package Week3;
public class TextBox extends Container {
public TextBox(String name) {
super(name);
}
}

Component.java

package Week3;
public abstract class Component {
protected String name;
public Component(String name) {
this.name = name;
}
public void print(){
System.out.println("print "+String.format("%s(%s)", this.getClass().getSimpleName(), name));
}
}

Button.java

package Week3;
public class Button extends Container {
public Button(String name) {
super(name);
}
}



用户头像

王铭铭

关注

还未添加个人签名 2020.01.14 加入

还未添加个人简介

评论

发布
暂无评论
架构师训练营第三周作业