Java
[Swing] FlowLayout
반나무
2020. 7. 4. 14:37
package swing.frame;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FlowLayoutFrame extends JFrame {
public FlowLayoutFrame(String title) {
//this없어도됨 //title설정
setTitle(title);
//size설정(width,height)
setSize(300, 300);
//위치 설정(x,y)
setLocation(800, 300);
//종료관리(보통 EXIT_ON_CLOSE를 사용, 상수3)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//레이아웃
setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
JButton b1 = new JButton("1");
add(b1);
JButton b2 = new JButton("2");
add(b2);
JButton b3 = new JButton("3");
add(b3);
JButton b4 = new JButton("4");
add(b4);
JButton b5 = new JButton("5");
add(b5);
setVisible(true);
}
public static void main(String[] args) {
//인수로 넣음
new FlowLayoutFrame("FlowLayout 프레임");
}
}
반응형