第三周作业一

发布于: 2020 年 06 月 24 日

手写单例模式类

打印输出窗口:

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)");

Label label1 = new Label("Label(用户名)");

TextBox textBox1 = new TextBox("TextBox(文本框)");

Label label2 = new Label("Label(密码)");

PasswordBox passwordBox = new PasswordBox("PasswordBox(密码框)");

CheckBox checkBox = new CheckBox("CheckBox(复选框)");

TextBox textBox2 = new TextBox("TextBox(记住用户名)");

Linklable linklable = new Linklable("Linklable(忘记密码)");

winForm.addWin(picture);

winForm.addWin(button1);

winForm.addWin(button2);

winForm.addWin(frame);

frame.addWin(label1);

frame.addWin(textBox1);

frame.addWin(label2);

frame.addWin(passwordBox);

frame.addWin(checkBox);

frame.addWin(textBox2);

frame.addWin(linklable);

winForm.print();

}

}

public interface Element {

void print();

String getName();

}

public class Frame implements Element {

List<Element> list = new ArrayList<Element>();

private String winName;

public Frame(String winName) {

this.winName = winName;

}

@Override

public void print() {

System.out.println(getName());

for(Element ele : list) {

ele.print();

}

}

public void addWin(Element element) {

list.add(element);

}

@Override

public String getName() {

return winName;

}

}

public class Piece implements Element {

private String winName;

public Piece(String winName) {

this.winName = winName;

}

@Override

public void print() {

System.out.println(getName());

}

@Override

public String getName() {

return winName;

}

}

public class Button extends Piece {

public Button(String winName) {

super(winName);

}

}

public class CheckBox extends Piece {

public CheckBox(String winName) {

super(winName);

}

}

public class Label extends Piece {

public Label(String winName) {

super(winName);

}

}

public class Linklable extends Piece {

public Linklable(String winName) {

super(winName);

}

}

public class PasswordBox extends Piece {

public PasswordBox(String winName) {

super(winName);

}

}

public class Picture extends Piece {

public Picture(String winName) {

super(winName);

}

}

public class TextBox extends Piece {

public TextBox(String winName) {

super(winName);

}

}

public class WinForm extends Frame{

public WinForm(String winName) {

super(winName);

}

}

用户头像

潜默闻雨

关注

还未添加个人签名 2018.11.23 加入

还未添加个人简介

评论

发布
暂无评论
第三周作业一