public interface Draw {
public abstract void print();
}
public class WinForm implements Draw{
private String name;
private Vector<Draw> drawVectors=new Vector<>();
public WinForm(String name){
this.name=name;
}
public void addDraw(Draw draw){
drawVectors.add(draw);
}
@Override
public void print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+name+")");
for(Draw each:drawVectors){
each.print();
}
}
}
public class Frame extends WinForm{
public Frame(String name) {
super(name);
}
}
public class Button implements Draw{
private String name;
public Button(String name){
this.name=name;
}
@Override
public void print() {
System.out.println("print "+this.getClass().getSimpleName()+"("+name+")");
}
}
public class DrawTest {
public static void main(String[] args) {
winForm().print();
}
public static Draw winForm() {
WinForm winForm=new WinForm("WINDOWS窗口");
winForm.addDraw(new Picture("LOGO图片"));
winForm.addDraw(new Button("登录"));
winForm.addDraw(new Button("注册"));
Frame frame1=new Frame("FRAME1");
frame1.addDraw(new Label("用户名"));
frame1.addDraw(new TextBox("文本框"));
frame1.addDraw(new Label("密码"));
frame1.addDraw(new PasswordBox("密码框"));
frame1.addDraw(new CheckBox("复选框"));
frame1.addDraw(new TextBox("记录用户名"));
frame1.addDraw(new LinkLabel("忘记密码"));
winForm.addDraw(frame1);
return winForm;
}
}
评论