流式布局 FlowLayout
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FirstFlowLayout {
public static void main(String[] args) {
Frame windows=new Frame("流式布局");
Button button1 = new Button("button1");
Button button2 = new Button("button2");
Button button3 = new Button("button3");
windows.setVisible(true);
windows.setBounds(200,200,350,350);
windows.setBackground(Color.green);
windows.setLayout(new FlowLayout(FlowLayout.RIGHT));
windows.add(button1);
windows.add(button2);
windows.add(button3);
windows.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
居中效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e110265698636a7b4fe0f658f3cc0316.png)
居左效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a5d803b14e7fe5e92af4b12176c36a61.png)
居右效果图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e002ab2a1fed86915315e00d400fdd88.png)