概要
这次主要学习Java中的图形界面的流式分布管理FlowLayout
代码
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class fiowlayout extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
new fiowlayout();
}
fiowlayout() {
/* 创建组件 */
JButton a = new JButton("东");
JButton b = new JButton("西");
JButton c = new JButton("南");
JButton d = new JButton("北");
JButton e = new JButton("中");
/* 改布局 */
this.setLayout(new FlowLayout());
/* 添加组件 */
this.add(a);
this.add(b);
this.add(c);
this.add(d);
this.add(e);
/* 创建窗口 */
this.setSize(400, 400);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);
}
}
小结
首先先布局
this.setLayout(new FlowLayout());
然后创建元素
在创建窗口容纳元素
窗口三步
创建大小
可以关闭
可以显示
this.setSize(400, 400);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setVisible(true);