第三周作业

用户头像
芒夏
关注
发布于: 2020 年 06 月 22 日
第三周作业

打印:

print WinForm(WINDOW窗口)

print Picture(LOGO图片)

print Button(登录)

print Button(注册)

print Frame(FRAME1)

print Lable(用户名)

print TextBox(文本框)

print Lable(密码)

print PasswordBox(密码框)

print CheckBox(复选框)

print Picture(记住用户名)

print LinkLable(忘记密码)



创建抽象类:

public abstract class WinLable {
public abstract void add(WinLable winLable);
public abstract void print();
}

子类:

public class WinForm extends WinLable {
private List<WinLable> winLableList = new ArrayList<>();
private String name;
public WinForm(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
winLableList.add(winLable);
}
@Override
public void print() {
System.out.println("print WinForm(" + name + ")");
for(WinLable obj : winLableList) {
obj.print();
}
}
}
public class TextBox extends WinLable {
private String name;
public TextBox(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
}
@Override
public void print() {
System.out.println("print TextBox(" + name + ")");
}
}
public class Picture extends WinLable {
private String name;
public Picture(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
}
@Override
public void print() {
System.out.println("print Picture(" + name + ")");
}
}
public class PasswordBox extends WinLable {
private String name;
public PasswordBox(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
}
@Override
public void print() {
System.out.println("print PasswordBox(" + name + ")");
}
}
public class LinkLable extends WinLable {
private String name;
public LinkLable(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
}
@Override
public void print() {
System.out.println("print LinkLable(" + name + ")");
}
}
public class Lable extends WinLable {
private String name;
public Lable(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
}
@Override
public void print() {
System.out.println("print Lable(" + name + ")");
}
}
public class Frame extends WinLable {
private List<WinLable> winLableList = new ArrayList<>();
private String name;
public Frame(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
winLableList.add(winLable);
}
@Override
public void print() {
System.out.println("print Frame(" + name + ")");
for(WinLable obj : winLableList) {
obj.print();
}
}
}
public class CheckBox extends WinLable {
private String name;
public CheckBox(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
}
@Override
public void print() {
System.out.println("print CheckBox(" + name + ")");
}
}
public class Button extends WinLable {
private String name;
public Button(String name) {
this.name = name;
}
@Override
public void add(WinLable winLable) {
}
@Override
public void print() {
System.out.println("print Button(" + name + ")");
}
}

Main:

public static void main(String[] args) {
WinLable winForm = new WinForm("WINDOW窗口");
WinLable picture = new Picture("LOGO图片");
WinLable button1 = new Button("登录");
WinLable button2 = new Button("注册");
WinLable frame = new Frame("FRAME1");
WinLable lable1 = new Lable("用户名");
WinLable textBox1 = new TextBox("文本框");
WinLable lable2 = new Lable("密码");
WinLable passwordBox = new PasswordBox("密码框");
WinLable checkBox = new CheckBox("复选框");
WinLable textBox2 = new Picture("记住用户名");
WinLable linkLable = new LinkLable("忘记密码");
frame.add(lable1);
frame.add(textBox1);
frame.add(lable2);
frame.add(passwordBox);
frame.add(checkBox);
frame.add(textBox2);
frame.add(linkLable);
winForm.add(picture);
winForm.add(button1);
winForm.add(button2);
winForm.add(frame);
winForm.print();
}

-------------------------------------------

手写单例模式:



用户头像

芒夏

关注

还未添加个人签名 2018.05.10 加入

还未添加个人简介

评论

发布
暂无评论
第三周作业