public class Mb extends Applet { public void init() {

FlowLayout flow=new FlowLayout();
                  flow.setAlignment(FlowLayout.LEFT);
flow.setHgap(20);
flow.setVgap(40);
setLayout(flow);//为什么不是用flow.setLayout(flow);
for(int i=1;i<=12;i++)
{
add(new Button("i am "+i));//为什么不是用flow.add(new Button("i am "+i));
}
                           }
}

解决方案 »

  1.   


    setLayout(flow);//为什么不是用flow.setLayout(flow);这是什么意思。
    flow自己设置自己???
    add(new Button("i am "+i));//为什么不是用flow.add(new Button("i am "+i));flow只是设置Applet的布局,最后还得把组件加到Applet上,不是加到布局上
      

  2.   

    第一··setLayout是设置一种布局管理器··而你new出来的flow就是一种布局管理器,前面有flow.是因为设置flow的属性··也就是你的布局管理器的属性··后面setLayout(flow);是将你设置好的布局管理器添加到当前的对象当中来
    第二··道理是一样的··意思是给当前对象添加button··
      

  3.   

    省略了:this,实际是this.setLayOut(flow);this指的是设置当前的Mb 的布局。
      

  4.   

    楼主没有弄清楚。java是面向对象的Button是个按钮。Layout是布局。布局当然要用在实在的容器上(JFrame)面拉。
    同样Button放哪里也知道了吧
      

  5.   

    那如果是这样:
    Container container=getContentPane();
    container.setLayout(new FlowLayout(FlowLayout.CENTER,10,20));
    这里省去container可不可以?有什么区别
      

  6.   

    public class Mb extends Applet {public void init() {FlowLayout flow=new FlowLayout();
      flow.setAlignment(FlowLayout.LEFT);
    flow.setHgap(20);
    flow.setVgap(40);
    setLayout(flow);//为什么不是用flow.setLayout(flow);
    for(int i=1;i<=12;i++)
    {
    add(new Button("i am "+i));//为什么不是用flow.add(new Button("i am "+i));
    }
      }
    }
    容器是哪个?
      

  7.   

    Container cp=getContantPane();
    cp.setLayout(flow);
      

  8.   

    flow不是容器 是流线型布局管理器,