forked from liujiboy/Java_Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowLayoutDemo.java
More file actions
28 lines (28 loc) · 888 Bytes
/
FlowLayoutDemo.java
File metadata and controls
28 lines (28 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package cqu.gui;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FlowLayoutDemo extends JFrame {
private JButton button1 = new JButton("First Button");
private JButton button2 = new JButton("Second Button");
private JButton button3 = new JButton("Third Button");
private JButton button4 = new JButton("Fourth Button");
public FlowLayoutDemo() {
setSize(300, 150);
setLocation(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//设置布局方式为FlowLayout
setLayout(new FlowLayout());
//添加按键,注意设置布局方式之后任何对
//组件进行设置的方法,例如setSize、
//setLocation等都会失效
add(button1);
add(button2);
add(button3);
add(button4);
}
public static void main(String arg[]) {
FlowLayoutDemo frame = new FlowLayoutDemo();
frame.setVisible(true);
}
}