写点什么

第三周作业 (作业一)

用户头像
Geek_83908e
关注
发布于: 2020 年 10 月 04 日





public abstract class Window {
String winName;
public abstract void Print();
public abstract String getName();
public abstract void setName(String name);
}
public class WinForm extends Window{
private List<Window> windowList = new ArrayList<>();
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
for(Window ele : windowList){
if(ele != null){
ele.Print();
}
}
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}
public class Picture extends Window{
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}
public class Button extends Window{
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}
public class Frame extends Window{
private List<Window> windowList = new ArrayList<>();
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
for(Window ele : windowList){
if(ele != null){
ele.Print();
}
}
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
public void addWindow(Window w){
if(w != null) windowList.add(w);
}
public void removeWindow(Window w){
if(w != null) windowList.remove(w);
}
}
public class Lable extends Window{
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}
public class TextBox extends Window{
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}
public class PasswordBox extends Window{
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}
public class CheckBox extends Window{
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}
public class LinkLable extends Window{
@Override
public void Print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+winName+")");
}
@Override
public String getName() {
return winName;
}
@Override
public void setName(String name) {
winName = name;
}
}



public class MainClass {
public static void main( String[] args ){
WinForm f1 = new WinForm();
f1.setName("WINDOW窗口");
Picture f2 = new Picture();
f2.setName("LOGO图片");
Button f3 = new Button();
f3.setName("登录");
Button f4 = new Button();
f4.setName("注册");
Frame f5 = new Frame();
f5.setName("FRAME1");
f1.addWindow(f2);
f1.addWindow(f3);
f1.addWindow(f4);
f1.addWindow(f5);
Lable f6 = new Lable();
f6.setName("用户名");
TextBox f7 = new TextBox();
f7.setName("文本框");
Lable f8 = new Lable();
f8.setName("密码");
PasswordBox f9 = new PasswordBox();
f9.setName("密码框");
CheckBox f10 = new CheckBox();
f10.setName("复选框");
TextBox f11 = new TextBox();
f11.setName("记住用户名");
LinkLable f12 = new LinkLable();
f12.setName("忘记秘密");
f5.addWindow(f6);
f5.addWindow(f7);
f5.addWindow(f8);
f5.addWindow(f9);
f5.addWindow(f10);
f5.addWindow(f11);
f5.addWindow(f12);
f1.Print();
}
}

最终打印结果如下:

print WinForm(WINDOW窗口)

print Picture(LOGO图片)

print Button(登录)

print Button(注册)

print Frame(FRAME1)

print Lable(用户名)

print TextBox(文本框)

print Lable(密码)

print PasswordBox(密码框)

print CheckBox(复选框)

print TextBox(记住用户名)

print LinkLable(忘记秘密)



发布于: 2020 年 10 月 04 日阅读数: 31
用户头像

Geek_83908e

关注

还未添加个人签名 2019.04.28 加入

还未添加个人简介

评论

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